From e5f37477c066233fd8ae3aeaaeeff992ea584d9a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 6 May 2021 21:44:34 +0200 Subject: [PATCH] cli: fix leak in print_wifi_connection() Found by Coverity: Error: RESOURCE_LEAK (CWE-772): [#def297] [important] NetworkManager-1.31.3/src/nmcli/devices.c:4610: alloc_fn: Storage is returned from allocation function "nm_utils_ssid_to_utf8". NetworkManager-1.31.3/src/nmcli/devices.c:4610: var_assign: Assigning: "ssid" = storage returned from "nm_utils_ssid_to_utf8(g_bytes_get_data(ssid_bytes, NULL), g_bytes_get_size(ssid_bytes))". NetworkManager-1.31.3/src/nmcli/devices.c:4612: noescape: Resource "ssid" is not freed or pointed-to in "g_print". NetworkManager-1.31.3/src/nmcli/devices.c:4642: noescape: Resource "ssid" is not freed or pointed-to in "string_append_mecard". NetworkManager-1.31.3/src/nmcli/devices.c:4654: leaked_storage: Variable "ssid" going out of scope leaks the storage it points to. # 4652| # 4653| g_print("\n"); # 4654|-> } # 4655| # 4656| static gboolean Fixes: 7061341a41d5 ('cli: add "nmcli d wifi show"') --- src/nmcli/devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nmcli/devices.c b/src/nmcli/devices.c index c165701b3d..9a22e5f775 100644 --- a/src/nmcli/devices.c +++ b/src/nmcli/devices.c @@ -4599,7 +4599,7 @@ print_wifi_connection(const NmcConfig *nmc_config, NMConnection *connection) const char * psk = NULL; const char * type = NULL; GBytes * ssid_bytes; - char * ssid; + gs_free char * ssid = NULL; GString * string; s_wireless = nm_connection_get_setting_wireless(connection);