Add some sanity checking for the "-i" argument.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 6 Jan 2004 02:58:20 +0000 (02:58 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 6 Jan 2004 02:58:20 +0000 (02:58 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@9573 f5534014-38df-0310-8fa8-9805f1628bb7

text2pcap.c

index b7cb2cef77c6ef853a5c4a84ea0d0a0458931255..97c153803b265b9f17b863fa66fec587c1406cc4 100644 (file)
@@ -6,7 +6,7 @@
  *
  * (c) Copyright 2001 Ashok Narayanan <ashokn@cisco.com>
  *
- * $Id: text2pcap.c,v 1.28 2004/01/05 19:31:44 ulfl Exp $
+ * $Id: text2pcap.c,v 1.29 2004/01/06 02:58:20 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -125,7 +125,7 @@ static unsigned long hdr_ethernet_proto = 0;
 
 /* Dummy IP header */
 static int hdr_ip = FALSE;
-static unsigned long hdr_ip_proto = 0;
+static long hdr_ip_proto = 0;
 
 /* Dummy UDP header */
 static int hdr_udp = FALSE;
@@ -1077,7 +1077,9 @@ parse_options (int argc, char *argv[])
 
         case 'i':
             hdr_ip = TRUE;
-            if (sscanf(optarg, "%ld", &hdr_ip_proto) < 1) {
+            hdr_ip_proto = strtol(optarg, &p, 10);
+            if (p == optarg || *p != '\0' || hdr_ip_proto < 0 ||
+                  hdr_ip_proto > 255) {
                 fprintf(stderr, "Bad argument for '-i': %s\n", optarg);
                 help(argv[0]);
             }