Fix dumpcap.c: Assigned value is garbage or undefined (clang analyzer)
authorHadriel Kaplan <hadrielk@yahoo.com>
Tue, 25 Feb 2014 16:25:47 +0000 (11:25 -0500)
committerEvan Huus <eapache@gmail.com>
Thu, 27 Feb 2014 17:57:02 +0000 (17:57 +0000)
Change-Id: I61dbf5e1e206b1c0d2e594bfba38e83e51e8f09c
Reviewed-on: https://code.wireshark.org/review/371
Reviewed-by: Evan Huus <eapache@gmail.com>
Tested-by: Evan Huus <eapache@gmail.com>
dumpcap.c

index ca282986ea52aa1c826f60893c80a31ba71c25b3..de7536cc0d23ebdd7a7b654c979c2d54d5a08270 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -1968,7 +1968,7 @@ cap_pipe_open_live(char *pipename,
     wchar_t *err_str;
 #endif
     ssize_t  b;
-    int      fd, sel_ret;
+    int      fd = -1, sel_ret;
     size_t   bytes_read;
     guint32  magic = 0;
 
@@ -2146,6 +2146,11 @@ cap_pipe_open_live(char *pipename,
         /* read the pcap header */
         bytes_read = 0;
         while (bytes_read < sizeof magic) {
+            if (fd == -1) {
+                g_snprintf(errmsg, errmsgl, "Invalid file descriptor");
+                goto error;
+            }
+
             sel_ret = cap_pipe_select(fd);
             if (sel_ret < 0) {
                 g_snprintf(errmsg, errmsgl,