From: Michael Tremer Date: Sat, 11 Jan 2025 14:32:06 +0000 (+0000) Subject: parser: Always copy the namespace to the stack X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f09aaee71c97c7ac7ad39907056ee2d1be3057f8;p=people%2Fric9%2Fpakfire.git parser: Always copy the namespace to the stack This avoids using strdupa() which will result in those functions not being possible to be inlined. Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/parser.c b/src/pakfire/parser.c index 3198202e5..0614cd73e 100644 --- a/src/pakfire/parser.c +++ b/src/pakfire/parser.c @@ -231,8 +231,8 @@ static struct pakfire_parser_declaration* pakfire_parser_get_declaration_recursi return NULL; } -static void pakfire_parser_strip_namespace(char** s) { - char* pos = strrchr(*s, '.'); +static void pakfire_parser_strip_namespace(char* s) { + char* pos = strrchr(s, '.'); if (pos) *pos = '\0'; @@ -265,11 +265,15 @@ static char* pakfire_parser_join(const char* c, const char* val1, const char* va static struct pakfire_parser_declaration* pakfire_parser_find_declaration( struct pakfire_parser* parser, const char* namespace, const char* name) { struct pakfire_parser_declaration* d = NULL; - char* n = NULL; + char n[NAME_MAX] = ""; + int r; // Create a working copy of namespace - if (namespace) - n = strdupa(namespace); + if (namespace) { + r = pakfire_string_set(n, namespace); + if (r < 0) + return NULL; + } for (;;) { d = pakfire_parser_get_declaration_recursive(parser, n, name); @@ -277,11 +281,11 @@ static struct pakfire_parser_declaration* pakfire_parser_find_declaration( return d; // End if we have exhausted the namespace - if (!n || !*n) + if (!*n) break; // Strip namespace - pakfire_parser_strip_namespace(&n); + pakfire_parser_strip_namespace(n); } // Nothing found @@ -592,6 +596,7 @@ ERROR: static int pakfire_parser_expand_variables(struct pakfire_parser* parser, const char* namespace, char** buffer) { + char parent_namespace[NAME_MAX]; pcre2_match_data* match = NULL; PCRE2_UCHAR* variable = NULL; PCRE2_SIZE variable_length = 0; @@ -651,8 +656,12 @@ static int pakfire_parser_expand_variables(struct pakfire_parser* parser, // Move up one step and lookup there if (namespace && *namespace) { - char* parent_namespace = strdupa(namespace); - pakfire_parser_strip_namespace(&parent_namespace); + r = pakfire_string_set(parent_namespace, namespace); + if (r < 0) + goto ERROR; + + // Strip + pakfire_parser_strip_namespace(parent_namespace); repl = pakfire_parser_get_raw(parser, parent_namespace, (const char*)variable);