diff options
author | teor <teor2345@gmail.com> | 2014-11-08 20:03:21 +1100 |
---|---|---|
committer | teor <teor2345@gmail.com> | 2014-11-08 20:26:53 +1100 |
commit | ce7fd6e160e2e3acb824b29e29afe15cd5e7bf4f (patch) | |
tree | 2b6dddef675c105f5c96c8329060ed4fa0930255 /src/common/util.c | |
parent | bac6d542c912f733aa6103c47ef41423848fef7c (diff) | |
download | tor-ce7fd6e160e2e3acb824b29e29afe15cd5e7bf4f.tar.gz tor-ce7fd6e160e2e3acb824b29e29afe15cd5e7bf4f.zip |
Stop crashing when a NULL filename is passed to file_status()
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.
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c index 2371ad3649..e850b14a16 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -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); |