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<TAB>

Fixes: 79bc271685 ('cli: TAB-completion for enum-style property values (rh #1034126)')
This commit is contained in:
Jan Vaclav 2024-08-20 16:23:23 +02:00 committed by Íñigo Huguet
parent 76285d321f
commit ca47fd882e

View file

@ -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;