Skip to content

Commit

Permalink
conf: init parser after check with stat()
Browse files Browse the repository at this point in the history
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: OISF#7302
(cherry picked from commit 87e6e93)
  • Loading branch information
zemeteri authored and victorjulien committed Oct 22, 2024
1 parent 1bf5550 commit 4f80cb5
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/conf-yaml-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,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) {
Expand All @@ -576,6 +571,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) {
Expand Down

0 comments on commit 4f80cb5

Please sign in to comment.