Overview
| Artifact ID: | be0d00d527cdffbe26886bac2fa9f901c8588af8 |
|---|---|
| Ticket: | 1095909fffffffffffffffffffffffffffffffff
Do not use readdir_r |
| User & Date: | jenglish on 2005-01-04 17:44:19 |
Changes
- assignee changed to: "mdejong"
- cmimetype changed to: "text/plain"
- 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().
- foundin changed to: "obsolete: 8.5a3"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "jenglish"
- subsystem changed to: "52. Portability Support"
- title changed to: "Do not use readdir_r"
- type changed to: "Bug"