From ca47fd882ed14fc70586d257b37b8d8178d1cd49 Mon Sep 17 00:00:00 2001 From: Jan Vaclav Date: Tue, 20 Aug 2024 16:23:23 +0200 Subject: [PATCH] nmcli/edit: fix memory leak in extract_setting_and_property In case the user selects a setting/property with "goto" command, and then attempts to tab-complete a setting/property pair, the original sett and prop strings are overriden without freeing: nmcli > goto 802-1x.pac-file nmcli 802-1x.pac-file> set 802-1.lal Fixes: 79bc2716852a ('cli: TAB-completion for enum-style property values (rh #1034126)') --- src/nmcli/connections.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c index 55e99fcfa7..65c5e34ba8 100644 --- a/src/nmcli/connections.c +++ b/src/nmcli/connections.c @@ -6584,8 +6584,15 @@ extract_setting_and_property(const char *prompt, const char *line, char **settin p2 = dot + 1; num1 = strcspn(p1, "."); num2 = len > num1 + 1 ? len - num1 - 1 : 0; - sett = num1 > 0 ? g_strndup(p1, num1) : sett; - prop = num2 > 0 ? g_strndup(p2, num2) : prop; + if (num1 > 0) { + g_free(sett); + sett = g_strndup(p1, num1); + } + + if (num2 > 0) { + g_free(prop); + prop = g_strndup(p2, num2); + } } else { if (!prop) prop = len > 0 ? g_strndup(p1, len) : NULL;