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".
This commit is contained in:
Guy Harris 2012-09-27 21:12:00 -07:00
parent e26b937957
commit fc058afcda

View File

@ -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;