]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
commandline parsing: check optarg ptr before using it 853/head
authorVictor Julien <victor@inliniac.net>
Wed, 26 Feb 2014 11:41:15 +0000 (12:41 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 26 Feb 2014 11:41:15 +0000 (12:41 +0100)
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.

src/suricata.c

index 64316c9abf65731def337fc484e74f7caae26b15..9bf971df37a825e0276b568ff22e8b44d034caa4 100644 (file)
@@ -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;