From 576513583b79031a9d1c46df71c9c9474bd4bac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Thu, 3 Jun 2021 16:34:05 +0200 Subject: [PATCH] pipewire: impl-module: limit module search depth Limit the depth of the recursive search done by `find_module()` to a sensible amount (at the moment: 8). --- src/pipewire/impl-module.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pipewire/impl-module.c b/src/pipewire/impl-module.c index 233373577..859f57a80 100644 --- a/src/pipewire/impl-module.c +++ b/src/pipewire/impl-module.c @@ -51,7 +51,7 @@ struct impl { /** \endcond */ -static char *find_module(const char *path, const char *name) +static char *find_module(const char *path, const char *name, int level) { char *filename; struct dirent *entry; @@ -72,6 +72,8 @@ static char *find_module(const char *path, const char *name) filename = NULL; /* now recurse down in subdirectories and look for it there */ + if (level <= 0) + return NULL; dir = opendir(path); if (dir == NULL) { @@ -91,9 +93,9 @@ static char *find_module(const char *path, const char *name) if (newpath == NULL) break; - if (stat(newpath, &s) == 0 && S_ISDIR(s.st_mode)) { - filename = find_module(newpath, name); - } + if (stat(newpath, &s) == 0 && S_ISDIR(s.st_mode)) + filename = find_module(newpath, name, level - 1); + free(newpath); if (filename != NULL) @@ -176,7 +178,7 @@ pw_context_load_module(struct pw_context *context, pw_log_debug("PIPEWIRE_MODULE_DIR set to: %s", module_dir); } - filename = find_module(module_dir, name); + filename = find_module(module_dir, name, 8); if (filename == NULL) goto error_not_found;