From: Frederic Marchal Date: Sun, 12 Jul 2015 17:43:27 +0000 (+0200) Subject: Don't delete anything from the temporary directory if unsure X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e9390734d9ba81d9c0ed5a3cb992f684b26a022e;p=thirdparty%2Fsarg.git Don't delete anything from the temporary directory if unsure Sarg must delete any previous stray temporary directory before filling it with the current log data. But sarg must not just delete any directory and its content if it isn't ours. Therefore, sarg check the directory content to make sure that it only contains files that may belong to us. There was an error in that routine. It would recursively delete directories found in the candidate temporary directory before making sure the whole directory content can be safely deleted. This problem is fixed here. --- diff --git a/util.c b/util.c index dac9d16..8be71f3 100644 --- a/util.c +++ b/util.c @@ -2324,9 +2324,7 @@ void emptytmpdir(const char *dir) debuga(__FILE__,__LINE__,_("Cannot stat \"%s\": %s\n"),dname,strerror(errno)); exit(EXIT_FAILURE); } - if (S_ISDIR(st.st_mode)) { - unlinkdir(dname,0); - } else if (!S_ISREG(st.st_mode)) { + if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode)) { debuga(__FILE__,__LINE__,_("Unknown path type for \"%s\". Check temporary directory\n"),dname); exit(EXIT_FAILURE); } @@ -2366,7 +2364,9 @@ void emptytmpdir(const char *dir) debuga(__FILE__,__LINE__,_("Cannot stat \"%s\": %s\n"),dname,strerror(errno)); exit(EXIT_FAILURE); } - if (S_ISREG(st.st_mode)) { + if (S_ISDIR(st.st_mode)) { + unlinkdir(dname,0); + } else if (S_ISREG(st.st_mode)) { if (unlink(dname)) { debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),dname,strerror(errno)); exit(EXIT_FAILURE);