From 130ac62c49a796d558f9b3b6a343bdac870a9cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Fri, 11 Mar 2016 11:26:44 +0200 Subject: nlplug-findfs: limit recursion depth Based on patch by donoban. Limit recursion depth for repository search to 2 levels (shell script had -maxdepth 3 for finding the file entry, so it's maximum of 2 levels of directories). For sysfs entries deeper search is allowed. ref #5192 --- nlplug-findfs.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/nlplug-findfs.c b/nlplug-findfs.c index b2b5ac8..b93a5a9 100644 --- a/nlplug-findfs.c +++ b/nlplug-findfs.c @@ -449,7 +449,7 @@ struct recurse_opts { }; /* pathbuf needs hold PATH_MAX chars */ -static void recurse_dir(char *pathbuf, struct recurse_opts *opts) +static void recurse_dir(char *pathbuf, struct recurse_opts *opts, int depth) { DIR *d = opendir(pathbuf); struct dirent *entry; @@ -492,9 +492,10 @@ static void recurse_dir(char *pathbuf, struct recurse_opts *opts) goto next; } - if (is_dir) - recurse_dir(pathbuf, opts); - else + if (is_dir) { + if (depth > 0) + recurse_dir(pathbuf, opts, depth - 1); + } else opts->callback(pathbuf, opts->userdata); next: pathbuf[pathlen] = '\0'; @@ -587,7 +588,7 @@ static int find_bootrepos(const char *devnode, const char *type, return 0; } - recurse_dir(mountdir, &opts); + recurse_dir(mountdir, &opts, 2); if (repos.count > 0) rc |= FOUND_BOOTREPO; @@ -804,9 +805,9 @@ static void *trigger_thread(void *data) }; char path[PATH_MAX] = "/sys/bus"; - recurse_dir(path, &opts); + recurse_dir(path, &opts, 8); strcpy(path, "/sys/devices"); - recurse_dir(path, &opts); + recurse_dir(path, &opts, 8); write(fd, &ok, sizeof(ok)); return NULL; } -- cgit v1.2.3