Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit 0fe32ce

Browse files
committed
Allow configuration to ban debuginfo from manifests
Use server.ini to optionally ban debuginfo from the manifests at configurable paths. Signed-off-by: Matthew Johnson <[email protected]>
1 parent 31aec46 commit 0fe32ce

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ dist_check_SCRIPTS = \
111111
test/functional/contentsize-across-versions-includes/test.bats \
112112
test/functional/delete-no-version-bump/test.bats \
113113
test/functional/file-name-blacklisted/test.bats \
114+
test/functional/file-name-debuginfo/test.bats \
114115
test/functional/format-no-decrement/test.bats \
115116
test/functional/full-run-delta/test.bats \
116117
test/functional/full-run/test.bats \

include/swupd.h

+2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ extern void release_configuration_data(void);
175175
extern char *config_image_base(void);
176176
extern char *config_output_dir(void);
177177
extern char *config_empty_dir(void);
178+
extern char *config_debuginfo_path(const char *path);
178179
extern int config_initial_version(void);
180+
extern bool config_ban_debuginfo(void);
179181

180182
extern void read_current_version(char *filename);
181183
extern void write_new_version(char *filename, int version);

server.ini

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
emptydir=/var/lib/update/empty/
33
imagebase=/var/lib/update/image/
44
outputdir=/var/lib/update/www/
5+
6+
[Debuginfo]
7+
banned=true
8+
lib=/usr/lib/debug/
9+
src=/usr/src/debug/

src/analyze_fs.c

+33
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,32 @@ static bool illegal_characters(const char *filename)
305305
return false;
306306
}
307307

308+
static bool illegal_path(const char *path)
309+
{
310+
bool ret = false;
311+
char *lib;
312+
char *src;
313+
314+
lib = config_debuginfo_path("lib");
315+
src = config_debuginfo_path("src");
316+
317+
// Don't allow debuginfo into the manifests
318+
if (lib && (strncmp(path, lib, strlen(lib)) == 0)) {
319+
ret = true;
320+
goto out;
321+
}
322+
323+
if (src && (strncmp(path, src, strlen(src)) == 0)) {
324+
ret = true;
325+
goto out;
326+
}
327+
328+
out:
329+
free(lib);
330+
free(src);
331+
return ret;
332+
}
333+
308334
static struct file *add_file(struct manifest *manifest,
309335
const char *entry_name,
310336
char *sub_filename,
@@ -314,6 +340,13 @@ static struct file *add_file(struct manifest *manifest,
314340
GError *err = NULL;
315341
struct file *file;
316342

343+
if (config_ban_debuginfo() && illegal_path(sub_filename)) {
344+
printf("WARNING: File %s is banned ...skipping.\n", sub_filename);
345+
free(sub_filename);
346+
free(fullname);
347+
return NULL;
348+
}
349+
317350
if (illegal_characters(entry_name)) {
318351
printf("WARNING: Filename %s includes illegal character(s) ...skipping.\n", sub_filename);
319352
free(sub_filename);

src/config.c

+14
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ int config_initial_version(void)
6767
return version;
6868
}
6969

70+
bool config_ban_debuginfo(void)
71+
{
72+
assert(keyfile != NULL);
73+
74+
return g_key_file_get_boolean(keyfile, "Debuginfo", "banned", NULL);
75+
}
76+
77+
char *config_debuginfo_path(const char *comp)
78+
{
79+
assert(keyfile != NULL);
80+
81+
return g_key_file_get_value(keyfile, "Debuginfo", comp, NULL);
82+
}
83+
7084
bool read_configuration_file(char *filename)
7185
{
7286
GError *error = NULL;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bats
2+
3+
# common functions
4+
load "../swupdlib"
5+
6+
setup() {
7+
clean_test_dir
8+
init_test_dir
9+
10+
init_server_ini
11+
set_latest_ver 0
12+
init_groups_ini os-core
13+
init_groups_ini test-bundle
14+
15+
set_os_release 10 os-core
16+
track_bundle 10 os-core
17+
set_os_release 10 test-bundle
18+
track_bundle 10 test-bundle
19+
20+
gen_file_plain 10 test-bundle "/usr/lib/debug/foo"
21+
gen_file_plain 10 test-bundle "/usr/src/debug/bar"
22+
gen_file_plain 10 test-bundle "/usr/bin/foobar"
23+
}
24+
25+
@test "debuginfo files pruned" {
26+
run sudo sh -c "$CREATE_UPDATE --osversion 10 --statedir $DIR --format 3"
27+
echo "$output"
28+
# This should not be pruned
29+
[[ 1 -eq $(grep '/usr/bin/foobar$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
30+
[[ 1 -eq $(grep '/usr/lib/debug$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
31+
[[ 1 -eq $(grep '/usr/src/debug$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
32+
# These should be pruned
33+
[[ 0 -eq $(grep '/usr/src/debug/bar$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
34+
[[ 0 -eq $(grep '/usr/lib/debug/foo$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
35+
36+
}
37+
38+
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80

0 commit comments

Comments
 (0)