]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't delete anything from the temporary directory if unsure
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 12 Jul 2015 17:43:27 +0000 (19:43 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 12 Jul 2015 17:43:27 +0000 (19:43 +0200)
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.

util.c

diff --git a/util.c b/util.c
index dac9d16c85993495aba34028e7c5c4f2c758155e..8be71f3ffb00a275fa7d32df88e36d7f837ac785 100644 (file)
--- 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);