From bba9edabeebd63313e042316724e04ef15c55efa Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 6 Jul 2021 12:00:34 +1000 Subject: [PATCH] conf: don't allow a NULL config name No functional changes, this is enforced by the only in-tree callers of pw_conf_load_conf() but let's enforce this properly. --- src/pipewire/conf.c | 5 +++++ test/test-config.c | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pipewire/conf.c b/src/pipewire/conf.c index 74a29f908..66f5fa812 100644 --- a/src/pipewire/conf.c +++ b/src/pipewire/conf.c @@ -254,6 +254,11 @@ static int conf_load(const char *prefix, const char *name, struct pw_properties struct stat sbuf; int fd; + if (name == NULL) { + pw_log_debug(NAME" %p: config name must not be NULL", conf); + return -EINVAL; + } + if (get_read_path(path, sizeof(path), prefix, name) == 0) { pw_log_debug(NAME" %p: can't load config '%s': %m", conf, path); return -ENOENT; diff --git a/test/test-config.c b/test/test-config.c index 99e9f2f02..52e3576dd 100644 --- a/test/test-config.c +++ b/test/test-config.c @@ -75,9 +75,24 @@ PWTEST(config_load_abspath) return PWTEST_PASS; } -PWTEST_SUITE(context) +PWTEST(config_load_nullname) { - pwtest_add(config_load_abspath, PWTEST_NOARG); + struct pw_properties *props = pw_properties_new("ignore", "me", NULL); + int r; + + r = pw_conf_load_conf(NULL, NULL, props); + pwtest_neg_errno(r, -EINVAL); + + r = pw_conf_load_conf("/dummy", NULL, props); + pwtest_neg_errno(r, -EINVAL); + + return PWTEST_PASS; +} + +PWTEST_SUITE(context) +{ + pwtest_add(config_load_abspath, PWTEST_NOARG); + pwtest_add(config_load_nullname, PWTEST_NOARG); return PWTEST_PASS; }