]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Stop crashing when a NULL filename is passed to file_status()
authorteor <teor2345@gmail.com>
Sat, 8 Nov 2014 09:03:21 +0000 (20:03 +1100)
committerteor <teor2345@gmail.com>
Sat, 8 Nov 2014 09:26:53 +0000 (20:26 +1100)
Stop crashing when a NULL filename is passed to file_status(),
instead, return FN_ERROR.
Also return FN_ERROR when a zero-length filename is passed to file_status().
Fixed as part of bug 13111.

changes/bug13111-generate-keys-on-empty-file [new file with mode: 0644]
src/common/util.c

diff --git a/changes/bug13111-generate-keys-on-empty-file b/changes/bug13111-generate-keys-on-empty-file
new file mode 100644 (file)
index 0000000..f6a56ef
--- /dev/null
@@ -0,0 +1,7 @@
+  o Minor bugfixes
+    - Stop crashing when a NULL filename is passed to file_status().
+      Fixed as part of bug 13111.
+
+  o Minor enhancements:
+    - Return FN_ERROR when a zero-length filename is passed to file_status().
+      Fixed as part of bug 13111.
index 2371ad364942144583e126152b929b3c4dcae0c5..e850b14a16e6fdbe21c199651f1c98433ef9473a 100644 (file)
@@ -1888,7 +1888,8 @@ clean_name_for_stat(char *name)
 #endif
 }
 
-/** Return FN_ERROR if filename can't be read, FN_NOENT if it doesn't
+/** Return FN_ERROR if filename can't be read, or is NULL or zero-length,
+ * FN_NOENT if it doesn't
  * exist, FN_FILE if it is a regular file, or FN_DIR if it's a
  * directory.  On FN_ERROR, sets errno. */
 file_status_t
@@ -1897,6 +1898,9 @@ file_status(const char *fname)
   struct stat st;
   char *f;
   int r;
+  if (!fname || strlen(fname) == 0) {
+    return FN_ERROR;
+  }
   f = tor_strdup(fname);
   clean_name_for_stat(f);
   log_debug(LD_FS, "stat()ing %s", f);