From: Zemeteri Kamimizu Date: Thu, 3 Oct 2024 09:50:31 +0000 (+0300) Subject: conf: init parser after check with stat() X-Git-Tag: suricata-8.0.0-beta1~806 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=87e6e9374ff40847d3e7408afcd404374b629337;p=thirdparty%2Fsuricata.git conf: init parser after check with stat() Commit changes are made to avoid possible memory leaks. If the parser is initialized before configuration file checking, there was no deinit call before function return. Do check config file existance and type before YAML parser initialization, so we don't need to deinit parser before exiting the function. Bug: #7302 --- diff --git a/src/conf-yaml-loader.c b/src/conf-yaml-loader.c index f70a5f04e8..d228efb5f8 100644 --- a/src/conf-yaml-loader.c +++ b/src/conf-yaml-loader.c @@ -558,11 +558,6 @@ ConfYamlLoadFileWithPrefix(const char *filename, const char *prefix) int ret; ConfNode *root = ConfGetNode(prefix); - if (yaml_parser_initialize(&parser) != 1) { - SCLogError("failed to initialize yaml parser."); - return -1; - } - struct stat stat_buf; /* coverity[toctou] */ if (stat(filename, &stat_buf) == 0) { @@ -574,6 +569,11 @@ ConfYamlLoadFileWithPrefix(const char *filename, const char *prefix) } } + if (yaml_parser_initialize(&parser) != 1) { + SCLogError("failed to initialize yaml parser."); + return -1; + } + /* coverity[toctou] */ infile = fopen(filename, "r"); if (infile == NULL) {