Tcl Library Source Code

View Ticket
Login
Ticket UUID: 1409177
Title: more secure alternative to [tempfile]
Type: RFE Version: None
Submitter: dgp Created on: 2006-01-18 16:26:07
Subsystem: fileutil Assigned To: nobody
Priority: 5 Medium Severity:
Status: Open Last Modified: 2009-04-11 03:31:12
Resolution: Closed By:
    Closed on:
Description:
The [tempfile] command creates
a new file and returns its name.

The caller is then free to
[open] that filename.

The separation of file creation
and the [open] leaves an interval
when an attacker might manipulate
that file.  So care must be taken
when using this facility.

A more secure strategy is to have
one command do all parts: generate
the file name, create and open
the file, and pass back the channel
of the open file in addition to
the file name.

This is analogous to using 
mkstmp() instead of tmpnam()
in a C program.

It would be good to either modify
[tempfile] to improve security, or
if compatibility is a concern, offer
an alternative command for the more
secure option.

Note there are some security issues
that cannot be addressed fully at
Tcl script level with Tcl's current
built-in commands, and will require
a C-coded solution.  See TIP 210.
User Comments: dgp added on 2009-04-11 03:31:12:
[file tempfile] is now part of Tcl 8.6.