mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 07:38:20 +02:00
libnm: fix logic and double free in nm_vpn_service_plugin_read_vpn_details()
"val" and "key" are now marked as nm_auto. They are freed at the end, and we should not free them before breaking the loop (at least not, without also clearing the variables). Fixes:02dbba49d6('libnm: fix leak in nm_vpn_service_plugin_read_vpn_details()') (cherry picked from commit62c1944e7d)
This commit is contained in:
parent
02fe804f32
commit
1192e7bbba
1 changed files with 3 additions and 12 deletions
|
|
@ -759,8 +759,7 @@ nm_vpn_service_plugin_read_vpn_details(int fd, GHashTable **out_data, GHashTable
|
||||||
nm_auto_free_gstring GString *val = NULL;
|
nm_auto_free_gstring GString *val = NULL;
|
||||||
nm_auto_free_gstring GString *line = NULL;
|
nm_auto_free_gstring GString *line = NULL;
|
||||||
char c;
|
char c;
|
||||||
|
GString * str = NULL;
|
||||||
GString *str = NULL;
|
|
||||||
|
|
||||||
if (out_data)
|
if (out_data)
|
||||||
g_return_val_if_fail(*out_data == NULL, FALSE);
|
g_return_val_if_fail(*out_data == NULL, FALSE);
|
||||||
|
|
@ -808,16 +807,12 @@ nm_vpn_service_plugin_read_vpn_details(int fd, GHashTable **out_data, GHashTable
|
||||||
/* finish marker */
|
/* finish marker */
|
||||||
break;
|
break;
|
||||||
} else if (strncmp(line->str, DATA_KEY_TAG, strlen(DATA_KEY_TAG)) == 0) {
|
} else if (strncmp(line->str, DATA_KEY_TAG, strlen(DATA_KEY_TAG)) == 0) {
|
||||||
if (key != NULL) {
|
if (nm_clear_g_string(&key))
|
||||||
g_warning("a value expected");
|
g_warning("a value expected");
|
||||||
g_string_free(key, TRUE);
|
|
||||||
}
|
|
||||||
key = g_string_new(line->str + strlen(DATA_KEY_TAG));
|
key = g_string_new(line->str + strlen(DATA_KEY_TAG));
|
||||||
str = key;
|
str = key;
|
||||||
hash = data;
|
hash = data;
|
||||||
} else if (strncmp(line->str, DATA_VAL_TAG, strlen(DATA_VAL_TAG)) == 0) {
|
} else if (strncmp(line->str, DATA_VAL_TAG, strlen(DATA_VAL_TAG)) == 0) {
|
||||||
if (val != NULL)
|
|
||||||
g_string_free(val, TRUE);
|
|
||||||
if (val || !key || hash != data) {
|
if (val || !key || hash != data) {
|
||||||
g_warning("%s not preceded by %s", DATA_VAL_TAG, DATA_KEY_TAG);
|
g_warning("%s not preceded by %s", DATA_VAL_TAG, DATA_KEY_TAG);
|
||||||
break;
|
break;
|
||||||
|
|
@ -825,16 +820,12 @@ nm_vpn_service_plugin_read_vpn_details(int fd, GHashTable **out_data, GHashTable
|
||||||
val = g_string_new(line->str + strlen(DATA_VAL_TAG));
|
val = g_string_new(line->str + strlen(DATA_VAL_TAG));
|
||||||
str = val;
|
str = val;
|
||||||
} else if (strncmp(line->str, SECRET_KEY_TAG, strlen(SECRET_KEY_TAG)) == 0) {
|
} else if (strncmp(line->str, SECRET_KEY_TAG, strlen(SECRET_KEY_TAG)) == 0) {
|
||||||
if (key != NULL) {
|
if (nm_clear_g_string(&key))
|
||||||
g_warning("a value expected");
|
g_warning("a value expected");
|
||||||
g_string_free(key, TRUE);
|
|
||||||
}
|
|
||||||
key = g_string_new(line->str + strlen(SECRET_KEY_TAG));
|
key = g_string_new(line->str + strlen(SECRET_KEY_TAG));
|
||||||
str = key;
|
str = key;
|
||||||
hash = secrets;
|
hash = secrets;
|
||||||
} else if (strncmp(line->str, SECRET_VAL_TAG, strlen(SECRET_VAL_TAG)) == 0) {
|
} else if (strncmp(line->str, SECRET_VAL_TAG, strlen(SECRET_VAL_TAG)) == 0) {
|
||||||
if (val != NULL)
|
|
||||||
g_string_free(val, TRUE);
|
|
||||||
if (val || !key || hash != secrets) {
|
if (val || !key || hash != secrets) {
|
||||||
g_warning("%s not preceded by %s", SECRET_VAL_TAG, SECRET_KEY_TAG);
|
g_warning("%s not preceded by %s", SECRET_VAL_TAG, SECRET_KEY_TAG);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue