]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Initialize some more variables
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Oct 2023 17:18:11 +0000 (17:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 2 Oct 2023 17:18:11 +0000 (17:18 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser.c

index a8869836c026029dc274119963155523d3586ae5..cea6e99a6d8710920771982898b2e2d2d58851b7 100644 (file)
@@ -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)