]> The Tcpdump Group git mirrors - tcpdump/commitdiff
More strictly check for numbers as arguments to -i.
authorGuy Harris <[email protected]>
Fri, 28 Sep 2012 04:12:00 +0000 (21:12 -0700)
committerGuy Harris <[email protected]>
Fri, 28 Sep 2012 04:12:00 +0000 (21:12 -0700)
Use strtol() and only treat the argument as a number if it's *all*
number, so that interface names such as 192_1_2 aren't treated as
"interface number 192".

tcpdump.c

index 0449ec8145394a0a5928aa389b2df923094ec6c2..fcc1b49992034575630842b47d1acf29f47dabfd 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -650,6 +650,7 @@ main(int argc, char **argv)
        char ebuf[PCAP_ERRBUF_SIZE];
        char *username = NULL;
        char *chroot_dir = NULL;
+       char *end;
 #ifdef HAVE_PCAP_FINDALLDEVS
        pcap_if_t *devpointer;
        int devnum;
@@ -803,7 +804,8 @@ main(int argc, char **argv)
                         * It can be useful on Windows, where more than
                         * one interface can have the same name.
                         */
-                       if ((devnum = atoi(optarg)) != 0) {
+                       devnum = strtol(optarg, &end, 10);
+                       if (optarg != end && *end == '\0') {
                                if (devnum < 0)
                                        error("Invalid adapter index");
 
@@ -922,9 +924,7 @@ main(int argc, char **argv)
                        Rflag = 0;
                        break;
 
-               case 's': {
-                       char *end;
-
+               case 's':
                        snaplen = strtol(optarg, &end, 0);
                        if (optarg == end || *end != '\0'
                            || snaplen < 0 || snaplen > MAXIMUM_SNAPLEN)
@@ -932,7 +932,6 @@ main(int argc, char **argv)
                        else if (snaplen == 0)
                                snaplen = MAXIMUM_SNAPLEN;
                        break;
-               }
 
                case 'S':
                        ++Sflag;