wireguard: fix crash in _auto_default_route_init()

#3  0x00007fb0aa9e7d3d in g_return_if_fail_warning
        (log_domain=log_domain@entry=0x562295fd5ee3 "libnm", pretty_function=pretty_function@entry=0x562295fd71d0 <__func__.35180> "_connection_get_setting_check", expression=expression@entry=0x562295f8edf7 "NM_IS_CONNECTION (connection)") at ../glib/gmessages.c:2767
    #4  0x0000562295df151a in _connection_get_setting_check (connection=0x0, setting_type=0x562297b17050 [NMSettingWireGuard/NMSetting]) at libnm-core/nm-connection.c:207
    #5  0x0000562295df151a in _connection_get_setting_check (connection=0x0, setting_type=0x562297b17050 [NMSettingWireGuard/NMSetting]) at libnm-core/nm-connection.c:205
    #6  0x0000562295ef132a in _nm_connection_get_setting (type=<optimized out>, connection=0x0) at ./libnm-core/nm-core-internal.h:483
    #7  0x0000562295ef132a in _auto_default_route_init (self=self@entry=0x562297bf82b0 [NMDeviceWireGuard]) at src/devices/nm-device-wireguard.c:443
    #8  0x0000562295ef1b98 in coerce_route_table (device=0x562297bf82b0 [NMDeviceWireGuard], addr_family=2, route_table=0, is_user_config=<optimized out>)
        at src/devices/nm-device-wireguard.c:565
    #9  0x0000562295ea42ae in _get_route_table (self=self@entry=0x562297bf82b0 [NMDeviceWireGuard], addr_family=addr_family@entry=2) at src/devices/nm-device.c:2311
    #10 0x0000562295ea4593 in nm_device_get_route_table (self=0x562297bf82b0 [NMDeviceWireGuard], addr_family=2) at src/devices/nm-device.c:2338
    #11 0x0000562295eabde0 in ip_config_merge_and_apply (self=0x562297bf82b0 [NMDeviceWireGuard], addr_family=2, commit=1) at src/devices/nm-device.c:7590
    #12 0x0000562295ed2f0b in device_link_changed (self=self@entry=0x562297bf82b0 [NMDeviceWireGuard]) at src/devices/nm-device.c:3939
    #13 0x00007fb0aa9dc7db in g_idle_dispatch (source=source@entry=0x562297bf0b30, callback=0x562295ed2880 <device_link_changed>, user_data=0x562297bf82b0) at ../glib/gmain.c:5627
    #14 0x00007fb0aa9dfedd in g_main_dispatch (context=0x562297a28090) at ../glib/gmain.c:3189
    #15 0x00007fb0aa9dfedd in g_main_context_dispatch (context=context@entry=0x562297a28090) at ../glib/gmain.c:3854
    #16 0x00007fb0aa9e0270 in g_main_context_iterate (context=0x562297a28090, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:3927
    #17 0x00007fb0aa9e05a3 in g_main_loop_run (loop=0x562297a0b380) at ../glib/gmain.c:4123
    #18 0x0000562295d0b147 in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:465

https://bugzilla.redhat.com/show_bug.cgi?id=1734383
This commit is contained in:
Thomas Haller 2019-07-30 18:38:48 +02:00
parent 72e0b522ff
commit 47fc1a4293

View file

@ -423,10 +423,10 @@ _auto_default_route_init (NMDeviceWireGuard *self)
{
NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE (self);
NMConnection *connection;
NMSettingWireGuard *s_wg;
gboolean enabled_v4;
gboolean enabled_v6;
gboolean enabled_v4 = FALSE;
gboolean enabled_v6 = FALSE;
gboolean refreshing_only;
guint32 new_fwmark = 0;
guint32 old_fwmark;
char sbuf1[100];
@ -436,40 +436,47 @@ _auto_default_route_init (NMDeviceWireGuard *self)
refreshing_only = priv->auto_default_route_initialized
&& priv->auto_default_route_refresh;
priv->auto_default_route_refresh = FALSE;
connection = nm_device_get_applied_connection (NM_DEVICE (self));
s_wg = _nm_connection_get_setting (connection, NM_TYPE_SETTING_WIREGUARD);
old_fwmark = priv->auto_default_route_fwmark;
priv->auto_default_route_fwmark = nm_setting_wireguard_get_fwmark (s_wg);
connection = nm_device_get_applied_connection (NM_DEVICE (self));
if (connection) {
NMSettingWireGuard *s_wg;
_auto_default_route_get_enabled (s_wg,
connection,
&enabled_v4,
&enabled_v6);
s_wg = _nm_connection_get_setting (connection, NM_TYPE_SETTING_WIREGUARD);
new_fwmark = nm_setting_wireguard_get_fwmark (s_wg);
_auto_default_route_get_enabled (s_wg,
connection,
&enabled_v4,
&enabled_v6);
}
if ( ( enabled_v4
|| enabled_v6)
&& new_fwmark == 0u) {
if (refreshing_only)
new_fwmark = old_fwmark;
else
new_fwmark = _auto_default_route_find_unused_table (nm_device_get_platform (NM_DEVICE (self)));
}
priv->auto_default_route_refresh = FALSE;
priv->auto_default_route_fwmark = new_fwmark;
priv->auto_default_route_enabled_4 = enabled_v4;
priv->auto_default_route_enabled_6 = enabled_v6;
priv->auto_default_route_initialized = TRUE;
if ( ( priv->auto_default_route_enabled_4
|| priv->auto_default_route_enabled_6)
&& priv->auto_default_route_fwmark == 0u) {
if (refreshing_only)
priv->auto_default_route_fwmark = old_fwmark;
else
priv->auto_default_route_fwmark = _auto_default_route_find_unused_table (nm_device_get_platform (NM_DEVICE (self)));
if (connection) {
_LOGT (LOGD_DEVICE,
"auto-default-route is %s for IPv4 and %s for IPv6%s",
priv->auto_default_route_enabled_4 ? "enabled" : "disabled",
priv->auto_default_route_enabled_6 ? "enabled" : "disabled",
priv->auto_default_route_enabled_4 || priv->auto_default_route_enabled_6
? nm_sprintf_buf (sbuf1, " (fwmark 0x%x)", priv->auto_default_route_fwmark)
: "");
}
_LOGT (LOGD_DEVICE,
"auto-default-route is %s for IPv4 and %s for IPv6%s",
priv->auto_default_route_enabled_4 ? "enabled" : "disabled",
priv->auto_default_route_enabled_6 ? "enabled" : "disabled",
priv->auto_default_route_enabled_4 || priv->auto_default_route_enabled_6
? nm_sprintf_buf (sbuf1, " (fwmark 0x%x)", priv->auto_default_route_fwmark)
: "");
}
static GPtrArray *