netsniff-ng: Check return value of poll()
authorTobias Klauser <tklauser@distanz.ch>
Mon, 12 Aug 2013 20:45:47 +0000 (12 22:45 +0200)
committerTobias Klauser <tklauser@distanz.ch>
Mon, 12 Aug 2013 20:45:47 +0000 (12 22:45 +0200)
The return value of two calls to poll() are never check, despite the
(unlikely) possibility of them returning an error, fix it by checking
the return value and panic()ing on error.

This issue was discovered using the Coverity scanner.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
netsniff-ng.c

index 0f35d04..682fb39 100644 (file)
@@ -343,7 +343,7 @@ static void receive_to_xmit(struct ctx *ctx)
 {
        short ifflags = 0;
        uint8_t *in, *out;
-       int rx_sock, ifindex_in, ifindex_out;
+       int rx_sock, ifindex_in, ifindex_out, ret;
        unsigned int size_in, size_out, it_in = 0, it_out = 0;
        unsigned long frame_count = 0;
        struct frame_map *hdr_in, *hdr_out;
@@ -473,7 +473,9 @@ static void receive_to_xmit(struct ctx *ctx)
                                goto out;
                }
 
-               poll(&rx_poll, 1, -1);
+               ret = poll(&rx_poll, 1, -1);
+               if (unlikely(ret < 0))
+                       panic("Poll failed!\n");
        }
 
        out:
@@ -982,7 +984,9 @@ static void recv_only_or_dump(struct ctx *ctx)
                                break;
                }
 
-               poll(&rx_poll, 1, -1);
+               ret = poll(&rx_poll, 1, -1);
+               if (unlikely(ret < 0))
+                       panic("Poll failed!\n");
        }
 
        bug_on(gettimeofday(&end, NULL));