From: Victor Julien Date: Wed, 26 Feb 2014 11:41:15 +0000 (+0100) Subject: commandline parsing: check optarg ptr before using it X-Git-Tag: suricata-2.0rc2~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F853%2Fhead;p=thirdparty%2Fsuricata.git commandline parsing: check optarg ptr before using it Fixes: ** CID 1075221: Dereference after null check (FORWARD_NULL) /src/suricata.c: 1344 in ParseCommandLine() The reason it gave this warning is that in other paths using optarg there was a check, so the checker assumed optarg can be NULL. --- diff --git a/src/suricata.c b/src/suricata.c index 64316c9abf..9bf971df37 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -1341,17 +1341,19 @@ static TmEcode ParseCommandLine(int argc, char** argv, SCInstance *suri) } #endif else if (strcmp((long_opts[option_index]).name, "set") == 0) { - char *val = strchr(optarg, '='); - if (val == NULL) { - SCLogError(SC_ERR_CMD_LINE, - "Invalid argument for --set, must be key=val."); - exit(EXIT_FAILURE); - } - *val++ = '\0'; - if (ConfSetFinal(optarg, val) != 1) { - fprintf(stderr, "Failed to set configuration value %s.", - optarg); - exit(EXIT_FAILURE); + if (optarg != NULL) { + char *val = strchr(optarg, '='); + if (val == NULL) { + SCLogError(SC_ERR_CMD_LINE, + "Invalid argument for --set, must be key=val."); + exit(EXIT_FAILURE); + } + *val++ = '\0'; + if (ConfSetFinal(optarg, val) != 1) { + fprintf(stderr, "Failed to set configuration value %s.", + optarg); + exit(EXIT_FAILURE); + } } } break;