This checks the return values of strdup() calls in tcpdrop(8).

OK?


Index: tcpdrop.c
===================================================================
RCS file: /cvs/src/usr.sbin/tcpdrop/tcpdrop.c,v
retrieving revision 1.12
diff -u -p -r1.12 tcpdrop.c
--- tcpdrop.c   24 Oct 2013 02:55:50 -0000      1.12
+++ tcpdrop.c   9 Jan 2014 22:50:43 -0000
@@ -54,6 +54,8 @@ main(int argc, char **argv)
 
        if (argc == 3) {
                laddr1 = addr1 = strdup(argv[1]);
+               if (!addr1)
+                       err(1, "strdup");
                port1 = strrchr(addr1, ':');
                if (port1)
                        *port1++ = '\0';
@@ -61,6 +63,8 @@ main(int argc, char **argv)
                        goto fail;
 
                faddr2 = addr2 = strdup(argv[2]);
+               if (!addr2)
+                       err(1, "strdup");
                port2 = strrchr(addr2, ':');
                if (port2)
                        *port2++ = '\0';
@@ -84,11 +88,15 @@ fail:
 
        if (addr1[0] == '[' && addr1[strlen(addr1) - 1] == ']') {
                laddr1 = strdup(addr1);
+               if (!laddr1)
+                       err(1, "strdup");
                laddr1[strlen(laddr1) - 1] = '\0';
                laddr1++;
        }
        if (addr2[0] == '[' && addr2[strlen(addr2) - 1] == ']') {
                faddr2 = strdup(addr2);
+               if (!faddr2)
+                       err(1, "strdup");
                faddr2[strlen(faddr2) - 1] = '\0';
                faddr2++;
        }

Reply via email to