From 4784c3214fd551c502fea77931921f791686fe39 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Fri, 26 Mar 2010 14:09:45 -0700 Subject: [PATCH] Fix bug 125. - Always bail on parse errors. - Exit if loading the config file fails. - Display the line number where the parsing failed. --- src/conf-yaml-loader.c | 11 +++++++---- src/suricata.c | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/conf-yaml-loader.c b/src/conf-yaml-loader.c index 8436f17..479d0aa 100644 --- a/src/conf-yaml-loader.c +++ b/src/conf-yaml-loader.c @@ -47,8 +47,9 @@ ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq) while (!done) { if (!yaml_parser_parse(parser, &event)) { - fprintf(stderr, "Failed to parse configuration file: %s\n", - parser->problem); + fprintf(stderr, + "Failed to parse configuration file at line %zu: %s\n", + parser->problem_mark.line, parser->problem); return -1; } @@ -128,10 +129,12 @@ ConfYamlParse(yaml_parser_t *parser, ConfNode *parent, int inseq) seq_node->name = SCCalloc(1, DEFAULT_NAME_LEN); snprintf(seq_node->name, DEFAULT_NAME_LEN, "%d", seq_idx++); TAILQ_INSERT_TAIL(&node->head, seq_node, next); - ConfYamlParse(parser, seq_node, 0); + if (ConfYamlParse(parser, seq_node, 0) != 0) + goto fail; } else { - ConfYamlParse(parser, node, inseq); + if (ConfYamlParse(parser, node, inseq) != 0) + goto fail; } state = CONF_KEY; } diff --git a/src/suricata.c b/src/suricata.c index 9cde7b1..e926dec 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -596,7 +596,10 @@ int main(int argc, char **argv) /* Load yaml configuration file if provided. */ if (conf_filename != NULL) { - ConfYamlLoadFile(conf_filename); + if (ConfYamlLoadFile(conf_filename) != 0) { + /* Error already displayed. */ + exit(EXIT_FAILURE); + } } else if (run_mode != MODE_UNITTEST){ SCLogError(SC_ERR_OPENING_FILE, "Configuration file has not been provided"); usage(argv[0]); -- 1.6.6.1