diff --git a/Makefile.am b/Makefile.am index 19cdfd6..d4cf9b2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -111,6 +111,7 @@ dist_check_SCRIPTS = \ test/functional/contentsize-across-versions-includes/test.bats \ test/functional/delete-no-version-bump/test.bats \ test/functional/file-name-blacklisted/test.bats \ + test/functional/file-name-debuginfo/test.bats \ test/functional/format-no-decrement/test.bats \ test/functional/full-run-delta/test.bats \ test/functional/full-run/test.bats \ diff --git a/include/swupd.h b/include/swupd.h index 1d492bd..2517eeb 100644 --- a/include/swupd.h +++ b/include/swupd.h @@ -175,7 +175,9 @@ extern void release_configuration_data(void); extern char *config_image_base(void); extern char *config_output_dir(void); extern char *config_empty_dir(void); +extern char *config_debuginfo_path(const char *path); extern int config_initial_version(void); +extern bool config_ban_debuginfo(void); extern void read_current_version(char *filename); extern void write_new_version(char *filename, int version); diff --git a/server.ini b/server.ini index f933833..812ad00 100644 --- a/server.ini +++ b/server.ini @@ -2,3 +2,8 @@ emptydir=/var/lib/update/empty/ imagebase=/var/lib/update/image/ outputdir=/var/lib/update/www/ + +[Debuginfo] +banned=true +lib=/usr/lib/debug/ +src=/usr/src/debug/ diff --git a/src/analyze_fs.c b/src/analyze_fs.c index de926a8..8418890 100644 --- a/src/analyze_fs.c +++ b/src/analyze_fs.c @@ -305,6 +305,32 @@ static bool illegal_characters(const char *filename) return false; } +static bool illegal_path(const char *path) +{ + bool ret = false; + char *lib; + char *src; + + lib = config_debuginfo_path("lib"); + src = config_debuginfo_path("src"); + + // Don't allow debuginfo into the manifests + if (lib && (strncmp(path, lib, strlen(lib)) == 0)) { + ret = true; + goto out; + } + + if (src && (strncmp(path, src, strlen(src)) == 0)) { + ret = true; + goto out; + } + +out: + free(lib); + free(src); + return ret; +} + static struct file *add_file(struct manifest *manifest, const char *entry_name, char *sub_filename, @@ -314,6 +340,13 @@ static struct file *add_file(struct manifest *manifest, GError *err = NULL; struct file *file; + if (config_ban_debuginfo() && illegal_path(sub_filename)) { + printf("WARNING: File %s is banned ...skipping.\n", sub_filename); + free(sub_filename); + free(fullname); + return NULL; + } + if (illegal_characters(entry_name)) { printf("WARNING: Filename %s includes illegal character(s) ...skipping.\n", sub_filename); free(sub_filename); diff --git a/src/config.c b/src/config.c index b0ce166..e7e0b48 100644 --- a/src/config.c +++ b/src/config.c @@ -67,6 +67,20 @@ int config_initial_version(void) return version; } +bool config_ban_debuginfo(void) +{ + assert(keyfile != NULL); + + return g_key_file_get_boolean(keyfile, "Debuginfo", "banned", NULL); +} + +char *config_debuginfo_path(const char *comp) +{ + assert(keyfile != NULL); + + return g_key_file_get_value(keyfile, "Debuginfo", comp, NULL); +} + bool read_configuration_file(char *filename) { GError *error = NULL; diff --git a/test/functional/file-name-debuginfo/test.bats b/test/functional/file-name-debuginfo/test.bats new file mode 100755 index 0000000..03be4a8 --- /dev/null +++ b/test/functional/file-name-debuginfo/test.bats @@ -0,0 +1,38 @@ +#!/usr/bin/env bats + +# common functions +load "../swupdlib" + +setup() { + clean_test_dir + init_test_dir + + init_server_ini + set_latest_ver 0 + init_groups_ini os-core + init_groups_ini test-bundle + + set_os_release 10 os-core + track_bundle 10 os-core + set_os_release 10 test-bundle + track_bundle 10 test-bundle + + gen_file_plain 10 test-bundle "/usr/lib/debug/foo" + gen_file_plain 10 test-bundle "/usr/src/debug/bar" + gen_file_plain 10 test-bundle "/usr/bin/foobar" +} + +@test "debuginfo files pruned" { + run sudo sh -c "$CREATE_UPDATE --osversion 10 --statedir $DIR --format 3" + echo "$output" + # This should not be pruned + [[ 1 -eq $(grep '/usr/bin/foobar$' $DIR/www/10/Manifest.test-bundle | wc -l) ]] + [[ 1 -eq $(grep '/usr/lib/debug$' $DIR/www/10/Manifest.test-bundle | wc -l) ]] + [[ 1 -eq $(grep '/usr/src/debug$' $DIR/www/10/Manifest.test-bundle | wc -l) ]] + # These should be pruned + [[ 0 -eq $(grep '/usr/src/debug/bar$' $DIR/www/10/Manifest.test-bundle | wc -l) ]] + [[ 0 -eq $(grep '/usr/lib/debug/foo$' $DIR/www/10/Manifest.test-bundle | wc -l) ]] + +} + +# vi: ft=sh ts=8 sw=2 sts=2 et tw=80