From 5aa0c7883b42126f7bd79fe362baaf959cfa1340 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Tue, 12 Jan 2010 09:24:39 -0800 Subject: [PATCH] Fix issue 55. Don't process any key/value pairs until we've hitting a mapping. --- src/conf-yaml-loader.c | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/src/conf-yaml-loader.c b/src/conf-yaml-loader.c index 9b88b45..ed4fc9c 100644 --- a/src/conf-yaml-loader.c +++ b/src/conf-yaml-loader.c @@ -227,6 +227,10 @@ ConfYamlParse(yaml_parser_t *parser) level--; break; case YAML_SCALAR_EVENT: + if (level < 0) { + /* Don't process values until we've hit a mapping. */ + continue; + } if (state == CONF_KEY) { if (key[level] != NULL) free(key[level]); @@ -412,6 +416,24 @@ logging:\n\ return 1; } +/** + * This test is mainly to make sure we don't segfaul when passed some + * other file. + */ +static int +ConfYamlNonYamlFileTest(void) +{ + ConfCreateContextBackup(); + ConfInit(); + + ConfYamlLoadFile("/etc/passwd"); + + ConfDeInit(); + ConfRestoreContextBackup(); + + return 1; +} + #endif /* UNITTESTS */ void @@ -420,5 +442,6 @@ ConfYamlRegisterTests(void) #ifdef UNITTESTS UtRegisterTest("ConfYamlRuleFileTest", ConfYamlRuleFileTest, 1); UtRegisterTest("ConfYamlLoggingOutputTest", ConfYamlLoggingOutputTest, 1); + UtRegisterTest("ConfYamlNonYamlFileTest", ConfYamlNonYamlFileTest, 1); #endif /* UNITTESTS */ } -- 1.6.5.2