Artifacts Associated With Ticket 2976497fffffffff
Ticket change [d895807aba] (rid 107467) by reeuwijk on 2010-03-25 14:32:56:
- assignee initialized to: "vincentdarley"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The function TclpCreateTempFile() in unix/tclUnixPipe.c makes a number of dangerous assumptions that could potentially lead to array bounds violations, or at least portability issues. The main problem is that an array fileName is declared with length L_tmpnam+9. This array is then filled with P_tmpdir, possibly a slash, and the string "tclXXXXXX". The code is written as if L_tmpnam is the length of P_tmpdir, but these two macros are entirely unrelated: L_tmpnam is the length of temporary filenames generated by the function tmpnam, and is unrelated to P_tmpdir. Thus, L_tmpnam could potentially be shorter than P_tmpdir (although I admit this is unlikely). Also, if L_tmpnam is supposed to represent the length of P_tmpdir, the 9 extra bytes are insufficient: the string "tclXXXXXX" is 9 characters long, but room for the possible '/' and a '\0' are also needed. A second assumption is that P_tmpdir is available in the first place.As far as I can tell P_tmpdir is not prescribed by any POSIX or C language standard, so blindly assuming that it is available, as tcl does, limits portability. One easy solution to all problems is to do something like #ifndef L_tmpdir #define L_tmpdir "/tmp" #endif char fileName[] = L_tmpdir "/tclXXXXXX"; With the only flaw that an L_tmpdir ending with a '/' would result in filenames with '//' in them, which might confuse some systems. (FYI, I came across this while porting tcl 8.5.8 to Minix.) - foundin initialized to: "obsolete: 8.5.8"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "reeuwijk"
- subsystem initialized to: "37. File System"
- title initialized to: "dangerous assumptions in TclpCreateTempFile"
- type initialized to: "Bug"