]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/pager: robust work with file descriptors [coverity scan]
authorKarel Zak <kzak@redhat.com>
Fri, 7 Sep 2012 11:29:55 +0000 (13:29 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Sep 2012 11:29:55 +0000 (13:29 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/pager.c

index 1fce5bf20e30935be53f109812626083e5d6b7fe..5cf8c03b5ef0fd77a841ce778596b3df3f3c964e 100644 (file)
@@ -17,6 +17,8 @@
 #include "xalloc.h"
 #include "nls.h"
 
+#define NULL_DEVICE    "/dev/null"
+
 void setup_pager(void);
 
 static const char *pager_argv[] = { "sh", "-c", NULL, NULL };
@@ -40,7 +42,10 @@ static inline void close_pair(int fd[2])
 
 static inline void dup_devnull(int to)
 {
-       int fd = open("/dev/null", O_RDWR);
+       int fd = open(NULL_DEVICE, O_RDWR);
+
+       if (fd < 0)
+               err(EXIT_FAILURE, _("cannot open %s"), NULL_DEVICE);
        dup2(fd, to);
        close(fd);
 }
@@ -70,7 +75,7 @@ static int start_command(struct child_process *cmd)
                if (need_in) {
                        dup2(fdin[0], 0);
                        close_pair(fdin);
-               } else if (cmd->in) {
+               } else if (cmd->in > 0) {
                        dup2(cmd->in, 0);
                        close(cmd->in);
                }