]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
PR25365: debuginfod-client: restrict cleanup to client-pattern files
authorAaron Merey <amerey@redhat.com>
Tue, 11 Feb 2020 20:54:55 +0000 (15:54 -0500)
committerFrank Ch. Eigler <fche@redhat.com>
Wed, 19 Feb 2020 19:01:33 +0000 (14:01 -0500)
Avoid deleting general files and directories in case a user
mis-sets $DEBUGINFOD_CACHE_PATH or accidentally moves a file
into the cache.

Signed-off-by: Aaron Merey <amerey@redhat.com>
debuginfod/ChangeLog
debuginfod/debuginfod-client.c
tests/ChangeLog
tests/run-debuginfod-find.sh

index d812e6d71ff09ffdef9b2c60db5c5666ebca0261..b297a3749702d957ce7f1e6fbd4dde9f5c5c63ec 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-19  Aaron Merey  <amerey@redhat.com>
+
+       * debuginfod-client.c (debuginfod_clean_cache): Restrict
+       cleanup to client-pattern files.
+
 2020-02-05  Frank Ch. Eigler  <fche@redhat.com>
 
        * debuginfod.cxx (argp options): Add -Z option.
index e5a2e824f7fe0c00c145b227c8380a7f79946049..186aa90a53bd1d9dbab9a7d5c153d1f2aa50735c 100644 (file)
@@ -50,6 +50,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <fts.h>
+#include <regex.h>
 #include <string.h>
 #include <stdbool.h>
 #include <linux/limits.h>
@@ -241,10 +242,19 @@ debuginfod_clean_cache(debuginfod_client *c,
   if (fts == NULL)
     return -errno;
 
+  regex_t re;
+  const char * pattern = ".*/[a-f0-9]+/(debuginfo|executable|source.*)$";
+  if (regcomp (&re, pattern, REG_EXTENDED | REG_NOSUB) != 0)
+    return -ENOMEM;
+
   FTSENT *f;
   long files = 0;
   while ((f = fts_read(fts)) != NULL)
     {
+      /* ignore any files that do not match the pattern.  */
+      if (regexec (&re, f->fts_path, 0, NULL, 0) != 0)
+        continue;
+
       files++;
       if (c->progressfn) /* inform/check progress callback */
         if ((c->progressfn) (c, files, 0))
@@ -268,7 +278,8 @@ debuginfod_clean_cache(debuginfod_client *c,
           ;
         }
     }
-  fts_close(fts);
+  fts_close (fts);
+  regfree (&re);
 
   /* Update timestamp representing when the cache was last cleaned.  */
   utime (interval_path, NULL);
index 1f55a2914a346e052f96257ded8d99da593dc591..01e4a0830a7ffba4cae26095400c24c39b1ae594 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-19  Aaron Merey  <amerey@redhat.com>
+
+       * run-debuginfod-find.sh: Test that files unrelated to debuginfod
+       survive cache cleaning.
+
 2020-02-08  Mark Wielaard  <mark@klomp.org>
 
        * run-pt_gnu_prop-tests.sh: New test.
index 1cc8f406e412be5f5a96ce6bd07b503c971ba72c..2964e7c077e5ed93e2e72b6b94499789de7dee96 100755 (executable)
@@ -365,6 +365,12 @@ testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
 
 ########################################################################
 
+# Add some files to the cache that do not fit its naming format.
+# They should survive cache cleaning.
+mkdir $DEBUGINFOD_CACHE_PATH/malformed
+touch $DEBUGINFOD_CACHE_PATH/malformed0
+touch $DEBUGINFOD_CACHE_PATH/malformed/malformed1
+
 # Trigger a cache clean and run the tests again. The clients should be unable to
 # find the target.
 echo 0 > $DEBUGINFOD_CACHE_PATH/cache_clean_interval_s
@@ -374,6 +380,12 @@ testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
 
 testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID2 && false || true
 
+if [ ! -f $DEBUGINFOD_CACHE_PATH/malformed0 ] \
+    || [ ! -f $DEBUGINFOD_CACHE_PATH/malformed/malformed1 ]; then
+  echo "unrelated files did not survive cache cleaning"
+  exit 1
+fi
+
 # Test debuginfod without a path list; reuse $PORT1
 env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d :memory: -p $PORT1 -L -F &
 PID3=$!