mirror of
https://github.com/the-tcpdump-group/tcpdump.git
synced 2024-12-03 15:04:34 +08:00
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:
parent
e9a15a0dab
commit
47a1858cb4
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user