]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: check `dirfd()` result
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 16 Oct 2024 10:54:45 +0000 (12:54 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 16 Oct 2024 11:30:25 +0000 (13:30 +0200)
`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 <equinox@opensourcerouting.org>
zebra/zebra_netns_notify.c

index 3ac4fdd737168ad0958f0008d0cceac78eeea1bd..52b94e040566e27c45f6a2edc6d945d82566b743 100644 (file)
@@ -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",