From 48f98032d4b7d625bdda43d0719767e011610272 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 29 Aug 2023 10:41:31 -0400 Subject: [PATCH] MT#55283 fix config parsing strategy Looks like glib at some point started resetting an existing string array that a config option is pointing to if that config option isn't present at all. Work around this by explicitly resetting the pointed-to variable to NULL, and then fixing up the contents on the second pass: either use the setting from the config file or the one from the command line, and free the other one. Change-Id: Ida89d71e54fc30b4cce3277107e2185737f54a51 --- lib/auxlib.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/auxlib.c b/lib/auxlib.c index 995e2eef3..cbdb72bbf 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -286,6 +286,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char e->description = NULL; CONF_OPTION_GLUE(string, char *); e->description = (void *) *s; + *s = NULL; break; } @@ -296,6 +297,7 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char e->description = NULL; CONF_OPTION_GLUE(string_list, char **, NULL); e->description = (void *) *s; + *s = NULL; break; } @@ -319,7 +321,9 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char case G_OPTION_ARG_STRING: case G_OPTION_ARG_FILENAME: { char **s = e->arg_data; - if (*s != e->description) + if (!*s && e->description) + *s = (char *) e->description; + else if (*s != e->description) g_free((void *) e->description); if (*s) { size_t len = strlen(*s); @@ -331,7 +335,9 @@ void config_load(int *argc, char ***argv, GOptionEntry *app_entries, const char case G_OPTION_ARG_STRING_ARRAY: { char ***s = e->arg_data; - if (*s != (void *) e->description) + if (!*s && e->description) + *s = (char **) e->description; + else if (*s != (void *) e->description) g_strfreev((void *) e->description); if (*s) { for (int i = 0; (*s)[i]; i++) {