Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: be0d00d527cdffbe26886bac2fa9f901c8588af8
Ticket: 1095909fffffffffffffffffffffffffffffffff
Do not use readdir_r
User & Date: jenglish on 2005-01-04 17:44:19
Changes

  1. assignee changed to: "mdejong"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    If Tcl is compiled with --enable-threads, it uses
    readdir_r() (or readdir64_r) instead of readdir().  
    This is unnecessary: according to the Single Unix
    Specification, "The pointer returned by readdir()
    points to data which may be overwritten by another call
    to readdir() on the same directory stream. This data is
    not overwritten by another call to readdir() on a
    different directory stream."  In other words: readdir()
    is perfectly thread-safe as long as you do not share
    the same DIR pointer across different threads (which
    Tcl does not do).
    
    In addition, Tcl does not allocate the correct amount
    of buffer space  for the path name (in fact, this is
    not even possible in general): the officially
    recommended mechanism is to set name_max =
    pathconf(dirname, _PC_NAME_MAX), then allocate a buffer
    of 'sizeof(struct dirent) + name_max + 1' bytes, since
    the maximum length of a filename (if there is a
    maximum) is filesystem-specific.
    
    This should prevent buffer overruns (assuming
    readdir_r() is implemented according to spec), but it
    can still truncate the filename -- on Linux, for
    example, it is documented that "[f]iles with name
    lengths longer than [...] _PC_NAME_MAX may exist in the
    given directory".
    
    Related issues: 1071701, 1001325, 723502.
    
    Attached patch (to follow) gets rid of the whole mess
    and just uses readdir().
    
  4. foundin changed to: "obsolete: 8.5a3"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "jenglish"
  9. subsystem changed to: "52. Portability Support"
  10. title changed to: "Do not use readdir_r"
  11. type changed to: "Bug"