]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
conf/yaml: don't allow empty key values
authorJason Ish <ish@unx.ca>
Wed, 7 Feb 2018 21:11:54 +0000 (15:11 -0600)
committerVictor Julien <victor@inliniac.net>
Tue, 13 Feb 2018 10:30:39 +0000 (11:30 +0100)
When loading an empty file, libyaml will fire a single scalar
event causing us to create a key that contains an empty string.
We're not interested in this, so skip an empty scalar value
when expecting a key.

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/2418

src/conf-yaml-loader.c

index c04ce1b1e218f51d9db47709d93e44d4faad3da8..5379c7b701c4e429ed4a8d7931be9e74704316f5 100644 (file)
@@ -206,6 +206,14 @@ ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq)
             char *tag = (char *)event.data.scalar.tag;
             SCLogDebug("event.type=YAML_SCALAR_EVENT; state=%d; value=%s; "
                 "tag=%s; inseq=%d", state, value, tag, inseq);
+
+            /* Skip over empty scalar values while in KEY state. This
+             * tends to only happen on an empty file, where a scalar
+             * event probably shouldn't fire anyways. */
+            if (state == CONF_KEY && strlen(value) == 0) {
+                goto next;
+            }
+
             if (inseq) {
                 char sequence_node_name[DEFAULT_NAME_LEN];
                 snprintf(sequence_node_name, DEFAULT_NAME_LEN, "%d", seq_idx++);