Skip to content
Tcl Source Code History Of Ticket 2976497fff
Login

History Of Ticket 2976497fff

Artifacts Associated With Ticket 2976497fff

  1. Ticket change [d895807aba] (rid 107467) by reeuwijk on 2010-03-25 14:32:56:

    1. assignee initialized to: "vincentdarley"
    2. cmimetype initialized to: "text/plain"
    3. 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.)
      
    4. foundin initialized to: "obsolete: 8.5.8"
    5. is_private initialized to: "0"
    6. priority initialized to: "5 Medium"
    7. resolution initialized to: "None"
    8. status initialized to: "Open"
    9. submitter initialized to: "reeuwijk"
    10. subsystem initialized to: "37. File System"
    11. title initialized to: "dangerous assumptions in TclpCreateTempFile"
    12. type initialized to: "Bug"