diff options
| author | Aaron Merey <amerey@redhat.com> | 2020-02-11 15:54:55 -0500 |
|---|---|---|
| committer | Frank Ch. Eigler <fche@redhat.com> | 2020-02-19 14:01:33 -0500 |
| commit | 889edd912ccbe4f0725319acec52edda29ec1584 (patch) | |
| tree | 7cb98daf400b701baff7b0dc59e4155848510a31 /debuginfod | |
| parent | c4600ae002c8a8738035ec5f80e818171811c9d4 (diff) | |
| download | platform_external_elfutils-889edd912ccbe4f0725319acec52edda29ec1584.tar.gz platform_external_elfutils-889edd912ccbe4f0725319acec52edda29ec1584.tar.bz2 platform_external_elfutils-889edd912ccbe4f0725319acec52edda29ec1584.zip | |
PR25365: debuginfod-client: restrict cleanup to client-pattern files
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>
Diffstat (limited to 'debuginfod')
| -rw-r--r-- | debuginfod/ChangeLog | 5 | ||||
| -rw-r--r-- | debuginfod/debuginfod-client.c | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index d812e6d7..b297a374 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -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. diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index e5a2e824..186aa90a 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -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); |
