Overview
| Artifact ID: | d895807abac512299ded6ad3eeb3e9f8aade6f6a |
|---|---|
| Ticket: | 2976497fffffffffffffffffffffffffffffffff
dangerous assumptions in TclpCreateTempFile |
| User & Date: | reeuwijk on 2010-03-25 14:32:56 |
Changes
- assignee changed to: "vincentdarley"
- cmimetype changed to: "text/plain"
- comment changed 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 changed to: "obsolete: 8.5.8"
- is_private changed to: "0"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "reeuwijk"
- subsystem changed to: "37. File System"
- title changed to: "dangerous assumptions in TclpCreateTempFile"
- type changed to: "Bug"