Coverity: TOCTOU: CID 392
authorNelson Ferreira <nelson.ferreira@ieee.org>
Wed, 22 Feb 2012 23:38:13 +0000 (18:38 -0500)
committerNelson Ferreira <nelson.ferreira@ieee.org>
Wed, 22 Feb 2012 23:38:13 +0000 (18:38 -0500)
* src/editfns.c (Ftemp_directory): First mkdir then properly
handle errors for the home directory temp directory creation.
Also attempt to create .created_by_sxemacs in case the dir exists.

Signed-off-by: Nelson Ferreira <nelson.ferreira@ieee.org>
src/editfns.c

index 4e52585..089b7f4 100644 (file)
@@ -619,12 +619,11 @@ On Unix it is obtained from TMPDIR, with /tmp as the default.
                        if ( home_env ) {
                                strncpy(path, home_env, sizeof(path)-1);
                                strncat(path, "/tmp/", sizeof(path)-1);
-                               if (stat(path, &st) < 0 && errno == ENOENT) {
+                               if ( mkdir(path, 0700) >= 0 || errno == EEXIST ) {
                                        int fd;
                                        char warnpath[
                                                /* strlen(".created_by_sxemacs") */
                                                19 + _POSIX_PATH_MAX + 1];
-                                       mkdir(path, 0700);      /* ignore retvals */
                                        strncpy(warnpath, path, _POSIX_PATH_MAX);
                                        warnpath[sizeof(warnpath)-1]=0;