]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
conf: init parser after check with stat()
authorZemeteri Kamimizu <zemeterisan@gmail.com>
Thu, 3 Oct 2024 09:50:31 +0000 (12:50 +0300)
committerVictor Julien <victor@inliniac.net>
Sat, 12 Oct 2024 09:03:37 +0000 (11:03 +0200)
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

src/conf-yaml-loader.c

index f70a5f04e88edae051db301bd2457c6f251f9bae..d228efb5f8e38191ee7a8387ebaf2c2bd5042e23 100644 (file)
@@ -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) {