From 3c13e279194f956a36b805d6d10de741730517ca Mon Sep 17 00:00:00 2001 From: Lance Fredrickson Date: Fri, 1 Dec 2023 12:43:27 -0700 Subject: [PATCH] Fix getall() hangup on non-regular files. (#11) If there's a directory within the nvram storage directory the getall function will stop there and stop processing more nvram value. This change then skips anything that is a non-regular file. --- nvram.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nvram.c b/nvram.c index 5cf7d00..4032fbf 100644 --- a/nvram.c +++ b/nvram.c @@ -494,6 +494,7 @@ int nvram_get_int(const char *key) { int nvram_getall(char *buf, size_t len) { char path[PATH_MAX] = MOUNT_POINT; + struct stat path_stat; struct dirent *entry; size_t pos = 0, ret; DIR *dir; @@ -520,6 +521,11 @@ int nvram_getall(char *buf, size_t len) { strncpy(path + strlen(MOUNT_POINT), entry->d_name, ARRAY_SIZE(path) - ARRAY_SIZE(MOUNT_POINT) - 1); path[PATH_MAX - 1] = '\0'; + stat(path, &path_stat); + if (!S_ISREG(path_stat.st_mode)) { + continue; + } + if ((ret = snprintf(buf + pos, len - pos, "%s=", entry->d_name)) != strlen(entry->d_name) + 1) { closedir(dir); sem_unlock();