From b3edc86e7888ce17291bef8523bae5e1b8c0cd8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= Date: Tue, 5 Feb 2013 10:00:58 +0100 Subject: [PATCH] cli: prevent possible crash if removing devices while nmcli running (bgo #693158) --- cli/src/connections.c | 9 ++++++--- cli/src/devices.c | 16 +++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cli/src/connections.c b/cli/src/connections.c index 09ce4f4ee3..d509ce0478 100644 --- a/cli/src/connections.c +++ b/cli/src/connections.c @@ -531,9 +531,12 @@ fill_in_fields_con_status (NMActiveConnection *active, GSList *con_list) devices = nm_active_connection_get_devices (active); for (i = 0; devices && (i < devices->len); i++) { NMDevice *device = g_ptr_array_index (devices, i); + const char *dev_iface = nm_device_get_iface (device); - g_string_append (dev_str, nm_device_get_iface (device)); - g_string_append_c (dev_str, ','); + if (dev_iface) { + g_string_append (dev_str, dev_iface); + g_string_append_c (dev_str, ','); + } } if (dev_str->len > 0) g_string_truncate (dev_str, dev_str->len - 1); /* Cut off last ',' */ @@ -1087,7 +1090,7 @@ find_device_for_connection (NmCli *nmc, if (iface) { const char *dev_iface = nm_device_get_iface (dev); - if ( !strcmp (dev_iface, iface) + if ( !g_strcmp0 (dev_iface, iface) && nm_device_connection_compatible (dev, connection, NULL)) { found_device = dev; } diff --git a/cli/src/devices.c b/cli/src/devices.c index caaf7102ca..52c8c8557a 100644 --- a/cli/src/devices.c +++ b/cli/src/devices.c @@ -833,8 +833,10 @@ show_device_info (gpointer data, gpointer user_data) NMDevice *slave = g_ptr_array_index (slaves, idx); const char *iface = nm_device_get_iface (slave); - g_string_append (bond_slaves_str, iface); - g_string_append_c (bond_slaves_str, ' '); + if (iface) { + g_string_append (bond_slaves_str, iface); + g_string_append_c (bond_slaves_str, ' '); + } } if (bond_slaves_str->len > 0) g_string_truncate (bond_slaves_str, bond_slaves_str->len-1); /* Chop off last space */ @@ -1018,7 +1020,7 @@ do_devices_list (NmCli *nmc, int argc, char **argv) NMDevice *candidate = g_ptr_array_index (devices, i); const char *dev_iface = nm_device_get_iface (candidate); - if (!strcmp (dev_iface, iface)) + if (!g_strcmp0 (dev_iface, iface)) device = candidate; } if (!device) { @@ -1182,7 +1184,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv) NMDevice *candidate = g_ptr_array_index (devices, i); const char *dev_iface = nm_device_get_iface (candidate); - if (!strcmp (dev_iface, iface)) + if (!g_strcmp0 (dev_iface, iface)) device = candidate; } @@ -1321,7 +1323,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) NMDevice *candidate = g_ptr_array_index (devices, i); const char *dev_iface = nm_device_get_iface (candidate); - if (!strcmp (dev_iface, iface)) { + if (!g_strcmp0 (dev_iface, iface)) { device = candidate; break; } @@ -1517,7 +1519,7 @@ find_wifi_device_by_iface (const GPtrArray *devices, const char *iface, int *idx if (iface) { /* If a iface was specified then use it. */ - if (strcmp (dev_iface, iface) == 0) { + if (g_strcmp0 (dev_iface, iface) == 0) { device = candidate; break; } @@ -1968,7 +1970,7 @@ do_device_wimax_list (NmCli *nmc, int argc, char **argv) NMDevice *candidate = g_ptr_array_index (devices, i); const char *dev_iface = nm_device_get_iface (candidate); - if (!strcmp (dev_iface, iface)) { + if (!g_strcmp0 (dev_iface, iface)) { device = candidate; break; } -- GitLab