Skip to content

Commit

Permalink
Fix getall() hangup on non-regular files. (#11)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lancethepants authored and Andrew Fasano committed Dec 17, 2023
1 parent 7cf4b46 commit 3c13e27
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nvram.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 3c13e27

Please sign in to comment.