From 97378a5bad8c20f4364b7fe86d96d9d14a192d48 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 6 Jan 2016 19:01:39 -0800 Subject: Don't assume a stat() fails only if the target file doesn't exist. If the error is something other than ENOENT, return that error indication. Change-Id: If866cab5f0de0e4fa8b1ed1cead1290feb88a3cb Reviewed-on: https://code.wireshark.org/review/13091 Reviewed-by: Guy Harris --- wsutil/filesystem.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'wsutil') diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index e8bdea325a..ec1a0b4c3b 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -1523,6 +1523,7 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return) #endif ws_statb64 s_buf; int ret; + int save_errno; if (profilename) { /* @@ -1537,7 +1538,18 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return) * If not then create it. */ pf_dir_path = get_profiles_dir (); - if (ws_stat64(pf_dir_path, &s_buf) != 0 && errno == ENOENT) { + if (ws_stat64(pf_dir_path, &s_buf) != 0) { + if (errno != ENOENT) { + /* Some other problem; give up now. */ + save_errno = errno; + *pf_dir_path_return = g_strdup(pf_dir_path); + errno = save_errno; + return -1; + } + + /* + * It doesn't exist; try to create it. + */ ret = ws_mkdir(pf_dir_path, 0755); if (ret == -1) { *pf_dir_path_return = g_strdup(pf_dir_path); @@ -1547,7 +1559,14 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return) } pf_dir_path = get_persconffile_dir(profilename); - if (ws_stat64(pf_dir_path, &s_buf) != 0 && errno == ENOENT) { + if (ws_stat64(pf_dir_path, &s_buf) != 0) { + if (errno != ENOENT) { + /* Some other problem; give up now. */ + save_errno = errno; + *pf_dir_path_return = g_strdup(pf_dir_path); + errno = save_errno; + return -1; + } #ifdef _WIN32 /* * Does the parent directory of that directory @@ -1566,6 +1585,16 @@ create_persconffile_profile(const char *profilename, char **pf_dir_path_return) if (pf_dir_parent_path_len > 0 && pf_dir_parent_path[pf_dir_parent_path_len - 1] != ':' && ws_stat64(pf_dir_parent_path, &s_buf) != 0) { + /* + * Not a drive letter and the stat() failed. + */ + if (errno != ENOENT) { + /* Some other problem; give up now. */ + save_errno = errno; + *pf_dir_path_return = g_strdup(pf_dir_path); + errno = save_errno; + return -1; + } /* * No, it doesn't exist - make it first. */ -- cgit v1.2.3