Overview
| Artifact ID: | 4b2081c008d48a9a4486f3939f2c3b8c169e7f8a |
|---|---|
| Ticket: | 442636ffffffffffffffffffffffffffffffffff
use of `tmpnam' is dangerous |
| User & Date: | lloydlim on 2001-07-19 01:38:24 |
Changes
- assignee changed to: "nobody"
- cmimetype changed to: "text/plain"
- comment changed to:
The following warning is produced when compiling Tcl on later versions of Linux and FreeBSD: /tmp/video4_Linux_2.2.19-7.0.1/mash-code/tcl8.3/unix/libtcl8.3.a(tclUnixPipe.o): In function `TclpCreateTempFile': tclUnixPipe.o(.text+0xef): the use of `tmpnam' is dangerous, better use `mkstemp' Comments in tclUnixPipe.c say "Linux says we should use mkstemp, but Solaris prefers tmpnam.". Please note that Solaris does _not_ prefer tmpnam, it prefers tmpfile (which is more similar to mkstemp than to tmpnam). This preference is just because tmpfile cleans up after itself. There is nothing wrong with mkstemp on Solaris. On the other hand, the use of tmpnam on Linux and FreeBSD is a security issue and generates a compile time warning. Therefore, I recommend that Tcl switch to using mkstemp. Here is a patch to replace tmpnam with mkstemp: --- tclUnixPipe.c.old Wed Jul 18 16:12:31 2001 +++ tclUnixPipe.c Wed Jul 18 17:50:34 2001 @@ -186,19 +186,21 @@ TclpCreateTempFile(contents) CONST char *contents; /* String to write into temp file, or NULL. */ { - char fileName[L_tmpnam], *native; + char fileName[L_tmpnam + 9], *native; Tcl_DString dstring; int fd; /* - * Linux says we should use mkstemp, but Solaris prefers tmpnam. - * We should also check against making more then TMP_MAX of these. + * We should check against making more than TMP_MAX of these. */ - if (tmpnam(fileName) == NULL) { /* INTL: Native. */ - return NULL; + strcpy(fileName, P_tmpdir); + if (fileName[strlen(fileName) - 1] != '/') { + strcat(fileName, "/"); } - fd = open(fileName, O_RDWR|O_CREAT|O_EXCL, 0666); /* INTL: Native. */ + strcat(fileName, "tclXXXXXX"); + fd = mkstemp(fileName); /* INTL: Native. */ if (fd == -1) { return NULL; } - foundin changed to: "obsolete: 8.3.3"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "lloydlim"
- subsystem changed to: "52. Portability Support"
- title changed to: "use of `tmpnam' is dangerous"
- type changed to: "Bug"