From 47a1858cb4ff90fe8dcbad4a6d5ff00afd7d1297 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 27 Sep 2012 21:12:00 -0700 Subject: [PATCH] More strictly check for numbers as arguments to -i. 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 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tcpdump.c b/tcpdump.c index 67b2a410..860f1488 100644 --- a/tcpdump.c +++ b/tcpdump.c @@ -628,6 +628,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; @@ -781,7 +782,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"); @@ -900,9 +902,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) @@ -910,7 +910,6 @@ main(int argc, char **argv) else if (snaplen == 0) snaplen = MAXIMUM_SNAPLEN; break; - } case 'S': ++Sflag;