]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Add sanity checks for command line argument handling
authorVictor Julien <victor@inliniac.net>
Mon, 23 Sep 2013 11:08:03 +0000 (13:08 +0200)
committerVictor Julien <victor@inliniac.net>
Mon, 23 Sep 2013 11:08:03 +0000 (13:08 +0200)
Coverity 1075221.

Normally getopt_long should cover this case, but can't hurt to
add in some extra checks.

src/suricata.c

index efd0d844053c61acf34c48a413f7beac34e30277..5b65700bb44c5c210a6fe06d07e69402ed0c9a88 100644 (file)
@@ -1292,6 +1292,11 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
         case 'i':
             memset(suri->pcap_dev, 0, sizeof(suri->pcap_dev));
 
+            if (optarg == NULL) {
+                SCLogError(SC_ERR_INITIALIZATION, "no option argument (optarg) for -i");
+                return TM_ECODE_FAILED;
+            }
+
             /* some windows shells require escaping of the \ in \Device. Otherwise
              * the backslashes are stripped. We put them back here. */
             if (strlen(optarg) > 9 && strncmp(optarg, "DeviceNPF", 9) == 0) {
@@ -1329,6 +1334,11 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
             }
             break;
         case 'l':
+            if (optarg == NULL) {
+                SCLogError(SC_ERR_INITIALIZATION, "no option argument (optarg) for -l");
+                return TM_ECODE_FAILED;
+            }
+
             if (ConfigSetLogDirectory(optarg) != TM_ECODE_OK) {
                 SCLogError(SC_ERR_FATAL, "Failed to set log directory.\n");
                 return TM_ECODE_FAILED;
@@ -1438,6 +1448,11 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri)
             suri->run_mode = RUNMODE_PRINT_VERSION;
             return TM_ECODE_OK;
         case 'F':
+            if (optarg == NULL) {
+                SCLogError(SC_ERR_INITIALIZATION, "no option argument (optarg) for -F");
+                return TM_ECODE_FAILED;
+            }
+
             SetBpfStringFromFile(optarg);
             break;
         default: