From: Michael Tremer Date: Mon, 2 Oct 2023 17:18:11 +0000 (+0000) Subject: parser: Initialize some more variables X-Git-Tag: 0.9.30~1557 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae90f3e0521ef57ebe24fa9e067ee26b602690e7;p=pakfire.git parser: Initialize some more variables Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/parser.c b/src/libpakfire/parser.c index a8869836c..cea6e99a6 100644 --- a/src/libpakfire/parser.c +++ b/src/libpakfire/parser.c @@ -523,11 +523,19 @@ ERROR: static int pakfire_parser_expand_variables(struct pakfire_parser* parser, const char* namespace, char** buffer) { - int r = 0; PCRE2_UCHAR* variable = NULL; - PCRE2_SIZE variable_length; + PCRE2_SIZE variable_length = 0; PCRE2_UCHAR* pattern = NULL; - PCRE2_SIZE pattern_length; + PCRE2_SIZE pattern_length = 0; + int r = 0; + + // Do not work on an empty buffer + if (!buffer) + return -EINVAL; + + // There is nothing to expend on empty strings + else if (!*buffer) + return 0; // Allocate memory for results pcre2_match_data* match = pcre2_match_data_create_from_pattern( @@ -595,16 +603,18 @@ static int pakfire_parser_expand_variables(struct pakfire_parser* parser, *buffer = tmp; // Free resources - pcre2_substring_free(variable); + if (variable) + pcre2_substring_free(variable); variable = NULL; - pcre2_substring_free(pattern); + if (pattern) + pcre2_substring_free(pattern); pattern = NULL; } ERROR: - pcre2_match_data_free(match); - + if (match) + pcre2_match_data_free(match); if (variable) pcre2_substring_free(variable); if (pattern)