From e6cb1a90f2fbeab421c79d2a740225413b3238ac Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 16 Oct 2024 12:54:45 +0200 Subject: [PATCH] zebra: check `dirfd()` result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `dirfd()` can theoretically return an error. Call it once and check the result. clang-SA: technically correctâ„¢. Ain't that the best kind of correct? Signed-off-by: David Lamparter --- zebra/zebra_netns_notify.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 3ac4fdd737..52b94e0405 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -378,19 +378,28 @@ void zebra_ns_notify_parse(void) { struct dirent *dent; DIR *srcdir = opendir(NS_RUN_DIR); + int srcdirfd; if (srcdir == NULL) { flog_err_sys(EC_LIB_SYSTEM_CALL, "NS parsing init: failed to parse %s", NS_RUN_DIR); return; } + + srcdirfd = dirfd(srcdir); + if (srcdirfd < 0) { + closedir(srcdir); + flog_err_sys(EC_LIB_SYSTEM_CALL, "NS parsing init: failed to parse %s", NS_RUN_DIR); + return; + } + while ((dent = readdir(srcdir)) != NULL) { struct stat st; if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) continue; - if (fstatat(dirfd(srcdir), dent->d_name, &st, 0) < 0) { + if (fstatat(srcdirfd, dent->d_name, &st, 0) < 0) { flog_err_sys( EC_LIB_SYSTEM_CALL, "NS parsing init: failed to parse entry %s",