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.
pull/853/head
Victor Julien 12 years ago
parent 9f2ce16ef3
commit 9442dce451

@ -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;

Loading…
Cancel
Save