NSIS/VPatch: code question
I'm syncing VPatch source with my personal version of the source code.
I have a question regarding temporary file creation on POSIX:
http://nsis.svn.sourceforge.net/view...l.cpp?view=log
"use the safer mkstemp instead of tmpnam"
However, I fail to see how the new code:
112 string getTempFile() {
113 char t[] = "/tmp/genpatXXXXXX";
114
115 mode_t old_umask = umask(0077);
116
117 int fd = mkstemp(t);
118 if (fd == -1) {
119 cerr << "Cannot create temporary filename";
120 return "";
121 }
122 close(fd);
123
124 umask(old_umask);
125
126 return string(t);
127 }
is any better than the old code:
114 string getTempFile() {
115 char filebuf [L_tmpnam];
116
117 // create a temporary filename
118 const char *fname = tmpnam (filebuf);
119
120 if (!fname)
121 cerr << "Cannot create temporary filename";
122
123 return string(fname);
124 }
The new code eliminates a warning about the usage of tmpnam (which is not secure against timing-based attacks). However, the new code isn't secure against this either: it creates a file securely, then it closes the file. And then permissions are set. However, between the setting of permissions and the closing of the file, hijacking of the temporary filename can take place, just as with tmpnam, right? Also, I don't like how the new code hardcodes temporary files to be stored in "/tmp", the old tmpnam() would get the folder from the OS.
I might be mistaken with my observations. Feedback on my (mis)conceptions is welcome!