summaryrefslogtreecommitdiff
path: root/libnm-util
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-12-18 13:01:23 +0100
committerThomas Haller <thaller@redhat.com>2015-12-18 14:50:00 +0100
commit8c27a370ff70430225bd6a2408e32e332f872f2e (patch)
tree2aab3c9fea975c7eef8a7f78edd8a9b877d1e63f /libnm-util
parentd830841d633eb7f79448fc8c2f2495a53c4f2ec5 (diff)
downloadNetworkManager-8c27a370ff70430225bd6a2408e32e332f872f2e.tar.gz
libnm-util: allow unknown setting types in nm_connection_get_virtual_iface_name()
Allow calling nm_connection_get_virtual_iface_name() on a non-verified connection by not asserting asserting against a valid base-setting. On nma-1-0 branch, nm-applet can crash with: #3 0x00007ffff2993a7a in g_assertion_message_expr (domain=0x7ffff51fad86 "libnm-util", file=0x7ffff51fb728 "nm-connection.c", line=320, func=0x7ffff51fc028 "_get_type_setting", expr=<optimized out>) at gtestutils.c:2444 #4 0x00007ffff51ac52f in _get_type_setting (connection=0xa3c160 [NMRemoteConnection]) at nm-connection.c:320 #5 0x00007ffff51ac341 in nm_connection_get_virtual_iface_name (connection=0xa3c160 [NMRemoteConnection]) at nm-connection.c:1436 #6 0x0000000000415bdc in add_virtual_items (type=type@entry=0x43c11d "bridge", all_devices=all_devices@entry=0x7f6580, all_connections=all_connections@entry=0x9354a0, menu=menu@entry=0x922990 [GtkMenu], applet=applet@entry=0x6cc000 [NMApplet]) at applet.c:1640 #7 0x00000000004176f6 in nma_menu_add_devices (menu=menu@entry=0x922990 [GtkMenu], applet=applet@entry=0x6cc000 [NMApplet]) at applet.c:1713 #8 0x0000000000418315 in nma_menu_show_cb (menu=0x922990 [GtkMenu], applet=0x6cc000 [NMApplet]) at applet.c:1974 where the connection type is "tun". Note that libnm accepts invalid connections and exposes them to the user (albeit issuing a warning). Later on there are many places where that can lead to further g_return*(), which is ugly indeed. At least, we should not assert against valid connections (because that crashes the user) and there is a well known fact that the base setting will be missing for tun settings. No need to even warn about that in nm_connection_get_virtual_iface_name() (we already got the warning during replace_settings).
Diffstat (limited to 'libnm-util')
-rw-r--r--libnm-util/nm-connection.c35
1 files changed, 11 insertions, 24 deletions
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index 884ed2e12c..ea1492b743 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -300,28 +300,6 @@ nm_connection_get_setting_by_name (NMConnection *connection, const char *name)
return type ? nm_connection_get_setting (connection, type) : NULL;
}
-/* not exposed until we actually need it */
-static NMSetting *
-_get_type_setting (NMConnection *connection)
-{
- NMSettingConnection *s_con;
- const char *type;
- NMSetting *base;
-
- g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
-
- s_con = nm_connection_get_setting_connection (connection);
- g_assert (s_con);
-
- type = nm_setting_connection_get_connection_type (s_con);
- g_assert (type);
-
- base = nm_connection_get_setting_by_name (connection, type);
- g_assert (base);
-
- return base;
-}
-
static gboolean
validate_permissions_type (GHashTable *hash, GError **error)
{
@@ -1429,12 +1407,21 @@ nm_connection_get_interface_name (NMConnection *connection)
const char *
nm_connection_get_virtual_iface_name (NMConnection *connection)
{
+ NMSettingConnection *s_con;
+ const char *type;
NMSetting *base;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
- base = _get_type_setting (connection);
- g_assert (base);
+ s_con = nm_connection_get_setting_connection (connection);
+ g_return_val_if_fail (s_con, NULL);
+
+ type = nm_setting_connection_get_connection_type (s_con);
+ g_return_val_if_fail (type, NULL);
+
+ base = nm_connection_get_setting_by_name (connection, type);
+ if (!base)
+ return NULL;
return nm_setting_get_virtual_iface_name (base);
}