]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib, ldpd: fix "argument cannot be negative" coverity warnings
authorRenato Westphal <renato@opensourcerouting.org>
Fri, 6 Oct 2017 00:47:11 +0000 (21:47 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Fri, 6 Oct 2017 01:51:23 +0000 (22:51 -0300)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ldpd/ldpd.c
lib/libfrr.c

index a79e63229fa700879484dd2fcbb8137cf7f0b805..843d160d626ae40cb8660b1be018e8fa028511ec 100644 (file)
@@ -450,10 +450,15 @@ start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync)
        }
 
        nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
-       dup2(nullfd, 0);
-       dup2(nullfd, 1);
-       dup2(nullfd, 2);
-       close(nullfd);
+       if (nullfd == -1) {
+               zlog_err("%s: failed to open /dev/null: %s", __func__,
+                        safe_strerror(errno));
+       } else {
+               dup2(nullfd, 0);
+               dup2(nullfd, 1);
+               dup2(nullfd, 2);
+               close(nullfd);
+       }
 
        if (dup2(fd_async, LDPD_FD_ASYNC) == -1)
                fatal("cannot setup imsg async fd");
index 2859f062c1f8594d8cfef331f7bd73eeb06d1b59..6cb8711edf15b95f40e4eaf9032ca6b8f78e4b4c 100644 (file)
@@ -768,6 +768,8 @@ void frr_vty_serv(void)
 
 static void frr_terminal_close(int isexit)
 {
+       int nullfd;
+
        if (daemon_ctl_sock != -1) {
                close(daemon_ctl_sock);
                daemon_ctl_sock = -1;
@@ -783,11 +785,16 @@ static void frr_terminal_close(int isexit)
                fflush(stdout);
        }
 
-       int nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
-       dup2(nullfd, 0);
-       dup2(nullfd, 1);
-       dup2(nullfd, 2);
-       close(nullfd);
+       nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
+       if (nullfd == -1) {
+               zlog_err("%s: failed to open /dev/null: %s", __func__,
+                        safe_strerror(errno));
+       } else {
+               dup2(nullfd, 0);
+               dup2(nullfd, 1);
+               dup2(nullfd, 2);
+               close(nullfd);
+       }
 }
 
 static struct thread *daemon_ctl_thread = NULL;
@@ -849,10 +856,15 @@ void frr_run(struct thread_master *master)
                }
        } else if (di->daemon_mode) {
                int nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
-               dup2(nullfd, 0);
-               dup2(nullfd, 1);
-               dup2(nullfd, 2);
-               close(nullfd);
+               if (nullfd == -1) {
+                       zlog_err("%s: failed to open /dev/null: %s", __func__,
+                                safe_strerror(errno));
+               } else {
+                       dup2(nullfd, 0);
+                       dup2(nullfd, 1);
+                       dup2(nullfd, 2);
+                       close(nullfd);
+               }
 
                if (daemon_ctl_sock != -1)
                        close(daemon_ctl_sock);