Jelajahi Sumber

Avoid fall-through if file matching temporary name exists

During checking whether a temporary name can be created, it may happen
that a file with this name already exists. Avoid falling through to
opening the file name in this case, and return with an error instead.

Signed-off-by: Sven Linker <sven.linker@kernkonzept.com>
Sven Linker 9 bulan lalu
induk
melakukan
41159c5cfd
1 mengubah file dengan 2 tambahan dan 1 penghapusan
  1. 2 1
      libc/misc/internals/tempname.c

+ 2 - 1
libc/misc/internals/tempname.c

@@ -218,7 +218,8 @@ int attribute_hidden __gen_tempname (char *tmpl, int kind, int flags,
 			    /* Give up now. */
 			    return -1;
 		    } else
-			fd = 0;
+			/* File already exists, so return with non-zero value */
+			return -1;
 		}
 	    case __GT_FILE:
 		fd = open (tmpl, O_RDWR | O_CREAT | O_EXCL | flags, mode);