core/wwan: avoid assertion failure in modem_ip{4,6}_config_result()

NMDeviceModem has priv->modem set from construction to dispose, and
the NM_MODEM_IP4_CONFIG_RESULT/NM_MODEM_IP6_CONFIG_RESULT signals
connected all the time.

On the other hand, NMModem may hook up to NMPPPManager's
NM_PPP_MANAGER_SIGNAL_IP{4,6}_CONFIG signals, which emit the
config-results signals. And PPP manager emits the config signals
from impl_ppp_manager_set_ip{4,6}_config().

That means, at any moment can be a D-Bus calls, which leads to emitting
those signals and calling into modem_ip4_config_result() and
modem_ip6_config_result().

At least, it's not clear from review what would prevent that from
happening. If you cannot easily verify that certain conditions are
satisfied, then this is not the place to assert, but to handle the case
as something that can happen regularly.

Handle signals in the unexpected state by ignoring them.

https://bugzilla.redhat.com/show_bug.cgi?id=1916192

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/926
This commit is contained in:
Thomas Haller 2021-07-12 21:35:38 +02:00
parent 416f97c5a9
commit fa786e1f46
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -193,15 +193,20 @@ modem_ip4_config_result(NMModem *modem, NMIP4Config *config, GError *error, gpoi
NMDeviceModem *self = NM_DEVICE_MODEM(user_data);
NMDevice * device = NM_DEVICE(self);
g_return_if_fail(nm_device_activate_ip4_state_in_conf(device) == TRUE);
if (!nm_device_activate_ip4_state_in_conf(device)) {
_LOGD(LOGD_MB | LOGD_IP4,
"retrieving IPv4 configuration while no longer in state IPv4 conf");
return;
}
if (error) {
_LOGW(LOGD_MB | LOGD_IP4, "retrieving IPv4 configuration failed: %s", error->message);
nm_device_ip_method_failed(device, AF_INET, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
} else {
nm_device_set_dev2_ip_config(device, AF_INET, NM_IP_CONFIG_CAST(config));
nm_device_activate_schedule_ip_config_result(device, AF_INET, NULL);
return;
}
nm_device_set_dev2_ip_config(device, AF_INET, NM_IP_CONFIG_CAST(config));
nm_device_activate_schedule_ip_config_result(device, AF_INET, NULL);
}
static void
@ -218,7 +223,11 @@ modem_ip6_config_result(NMModem * modem,
gs_unref_object NMIP6Config *ignored = NULL;
gboolean got_config = !!config;
g_return_if_fail(nm_device_activate_ip6_state_in_conf(device) == TRUE);
if (!nm_device_activate_ip6_state_in_conf(device)) {
_LOGD(LOGD_MB | LOGD_IP6,
"retrieving IPv6 configuration while no longer in state IPv6 conf");
return;
}
if (error) {
_LOGW(LOGD_MB | LOGD_IP6, "retrieving IPv6 configuration failed: %s", error->message);