From: Victor Julien Date: Mon, 23 Sep 2013 11:08:03 +0000 (+0200) Subject: Add sanity checks for command line argument handling X-Git-Tag: suricata-2.0beta2~346 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=397a55457d3d23fd628e0a07505f7c4bd9387de2;p=thirdparty%2Fsuricata.git Add sanity checks for command line argument handling Coverity 1075221. Normally getopt_long should cover this case, but can't hurt to add in some extra checks. --- diff --git a/src/suricata.c b/src/suricata.c index efd0d84405..5b65700bb4 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -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: