From 8b74ac6ba00c40fd252698b6938ea5bcda39163b Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Wed, 7 Feb 2018 15:11:54 -0600 Subject: [PATCH] conf/yaml: don't allow empty key values 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/conf-yaml-loader.c b/src/conf-yaml-loader.c index c04ce1b1e2..5379c7b701 100644 --- a/src/conf-yaml-loader.c +++ b/src/conf-yaml-loader.c @@ -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++);