From 5e2d58573b7add7cf95b9c716e84c731c73bf4b9 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sat, 11 Jan 2025 14:08:43 +0000 Subject: [PATCH] parser: Cleanup expanding variables Signed-off-by: Michael Tremer --- src/pakfire/parser.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/pakfire/parser.c b/src/pakfire/parser.c index b6a862f14..a4984569a 100644 --- a/src/pakfire/parser.c +++ b/src/pakfire/parser.c @@ -703,6 +703,7 @@ ERROR: char* pakfire_parser_expand(struct pakfire_parser* parser, const char* namespace, const char* value) { + char* buffer = NULL; int r; // Return NULL when the value is NULL @@ -710,25 +711,27 @@ char* pakfire_parser_expand(struct pakfire_parser* parser, return NULL; // Create a working copy of the string we are expanding - char* buffer = strdup(value); + buffer = strdup(value); + if (!buffer) + goto ERROR; // Fast path to check if there are any variables in here whatsoever - char* pos = strchr(value, '%'); + char* pos = strchr(buffer, '%'); if (!pos) return buffer; // Expand all variables r = pakfire_parser_expand_variables(parser, namespace, &buffer); - if (r) { - DEBUG(parser->ctx, "Failed to expand variables in '%s': %m\n", value); + if (r < 0) { + DEBUG(parser->ctx, "Failed to expand variables in '%s': %s\n", value, strerror(-r)); goto ERROR; } // Expand all commands if (parser->flags & PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS) { r = pakfire_parser_expand_commands(parser, &buffer); - if (r) { - DEBUG(parser->ctx, "Failed to expand commands in '%s': %m\n", value); + if (r < 0) { + DEBUG(parser->ctx, "Failed to expand commands in '%s': %s\n", value, strerror(-r)); goto ERROR; } } -- 2.47.3