From 69c248a431443a7a168df9a94857533429fab055 Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Fri, 18 Jul 2025 14:15:38 -0300 Subject: [PATCH 1/3] parser: initialize non-static variable Fix issues introduced in coverity's snapshot 89167 - CID 532798: (#1 of 1): Uninitialized scalar field (UNINIT_CTOR) Signed-off-by: Georgia Garcia --- parser/variable.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/parser/variable.cc b/parser/variable.cc index c43062e7a..97398761b 100644 --- a/parser/variable.cc +++ b/parser/variable.cc @@ -24,7 +24,8 @@ variable::variable(const char *var_name, struct value_list *values): type(sd_set), - var_name(var_name) + var_name(var_name), + boolean(false) /* not used */ { struct value_list *entry = NULL; if (!values || !values->value) { @@ -39,7 +40,8 @@ variable::variable(const char *var_name, struct value_list *values): variable::variable(const char *var_name, const char *value): type(sd_set), - var_name(var_name) + var_name(var_name), + boolean(false) /* not used */ { PDEBUG("Matched: set assignment for (%s)\n", var_name); this->values.insert(value); From e4f3ef72ab254f06435f3a9e05c9a29efbecb179 Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Fri, 18 Jul 2025 14:23:49 -0300 Subject: [PATCH 2/3] parser: use const auto & to avoid copy Fix issues introduced in coverity's snapshot 89167 - CID 532797: (#1 of 1): Use of auto that causes a copy (AUTO_CAUSES_COPY) Signed-off-by: Georgia Garcia --- parser/variable.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/parser/variable.cc b/parser/variable.cc index 97398761b..ece539fb8 100644 --- a/parser/variable.cc +++ b/parser/variable.cc @@ -280,7 +280,7 @@ int variable::expand_variable() expanding = true; std::list work_set(values.begin(), values.end()); - for (auto value : work_set) { + for (const auto &value : work_set) { auto result = extract_variable(value); std::string prefix = std::get<0>(result); std::string var = std::get<1>(result); @@ -313,7 +313,7 @@ int variable::expand_variable() ref->var_name.c_str()); exit(1); } - for (auto refvalue : ref->expanded) { + for (const auto &refvalue : ref->expanded) { /* there could still be vars in suffix, so add * to work_set, not expanded */ work_set.push_back(prefix + refvalue + suffix); @@ -327,7 +327,7 @@ out: void variable::dump_set_values(std::set values) { - for (auto value : values) + for (const auto &value : values) printf(" \"%s\"", value.c_str()); } From efb13aac0aff3f5ec6ee16c12d1f6c56d327cc6b Mon Sep 17 00:00:00 2001 From: Georgia Garcia Date: Fri, 18 Jul 2025 14:26:35 -0300 Subject: [PATCH 3/3] parser: fix leaks from variable refactoring Fix issues introduced in coverity's snapshot 89167 - CID 532796: (#4 of 4): Resource leak (RESOURCE_LEAK) Signed-off-by: Georgia Garcia --- parser/parser_variable.c | 18 +++++++++++++----- parser/symtab.cc | 13 +++++++++---- parser/variable.cc | 4 +++- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/parser/parser_variable.c b/parser/parser_variable.c index af3bd7791..857c474d1 100644 --- a/parser/parser_variable.c +++ b/parser/parser_variable.c @@ -140,6 +140,7 @@ int process_profile_variables(Profile *prof) int error = 0; variable *saved_exec_path = NULL; variable *saved_attach_path = NULL; + variable *tmp = NULL; /* needs to be before PROFILE_NAME_VARIABLE so that variable will * have the correct name @@ -185,18 +186,25 @@ cleanup: * don't support that yet. */ if (prof->attachment) { - symtab::delete_var(PROFILE_EXEC_VAR); - if (saved_exec_path) + tmp = symtab::delete_var(PROFILE_EXEC_VAR); + delete tmp; + if (saved_exec_path) { symtab::add_var(*saved_exec_path); + delete saved_exec_path; + } } cleanup_attach: if (prof->attachment) { - symtab::delete_var(PROFILE_ATTACH_VAR); - if (saved_attach_path) + tmp = symtab::delete_var(PROFILE_ATTACH_VAR); + delete tmp; + if (saved_attach_path) { symtab::add_var(*saved_attach_path); + delete saved_attach_path; + } } cleanup_name: - symtab::delete_var(PROFILE_NAME_VARIABLE); + tmp = symtab::delete_var(PROFILE_NAME_VARIABLE); + delete tmp; out: return error; diff --git a/parser/symtab.cc b/parser/symtab.cc index 12e89e240..b72a8ec10 100644 --- a/parser/symtab.cc +++ b/parser/symtab.cc @@ -139,13 +139,16 @@ variable *symtab::get_set_var(const char *name) char *var_name = variable::process_var(name); variable *var = lookup_existing_symbol(var_name); if (!var) { - return var; + goto out; } if (var->type != sd_set) { PERROR("Variable %s is not a set variable\n", var_name); - return nullptr; + var = nullptr; + goto out; } var->expand_variable(); +out: + free(var_name); return var; } @@ -154,12 +157,14 @@ variable *symtab::get_boolean_var(const char *name) char *var_name = variable::process_var(name); variable *var = lookup_existing_symbol(var_name); if (!var) { - return var; + goto out; } if (var->type != sd_boolean) { PERROR("Variable %s is not a boolean variable\n", var_name); - return nullptr; + var = nullptr; + goto out; } +out: free(var_name); return var; } diff --git a/parser/variable.cc b/parser/variable.cc index ece539fb8..686b85720 100644 --- a/parser/variable.cc +++ b/parser/variable.cc @@ -265,6 +265,7 @@ int variable::expand_by_alternation(char **name) int variable::expand_variable() { + char *name = NULL; int rc = 0; if (type == sd_boolean) { @@ -290,7 +291,7 @@ int variable::expand_variable() expanded.insert(value); /* no var left to expand */ continue; } - char *name = variable::process_var(var.c_str()); + name = variable::process_var(var.c_str()); variable *ref = symtab::lookup_existing_symbol(name); if (!ref) { PERROR("Failed to find declaration for: %s\n", var.c_str()); @@ -321,6 +322,7 @@ int variable::expand_variable() } out: + free(name); expanding = false; return rc; }