bearer-mbim: don't crash when modem doesn't send gateways

When the Ericsson F5321 with firmware R3C11/R4D04 is told to make
an IPv6-only connection, it reports that it has IPv4 configuration
but then returns no actual addresses.  Check both the flags and
actual data before trying to use them.

ModemManager[25850]: <debug> [1506958721.914717] IPv4 configuration available: 'address, gateway, dns, mtu'
ModemManager[25850]: <debug> [1506958721.914731]   IP addresses (0)
ModemManager[25850]: <debug> [1506958721.914741]   DNS addresses (0)
ModemManager[25850]: <debug> [1506958721.914748]   MTU: '0'
ModemManager[25850]: <debug> [1506958721.914758] IPv6 configuration available: 'address, dns, mtu'
ModemManager[25850]: <debug> [1506958721.914767]   IP addresses (1)
ModemManager[25850]: <debug> [1506958721.914852]     IP [0]: 'fe80::39:f622:7d01/64'
ModemManager[25850]: <debug> [1506958721.914866]   DNS addresses (2)
ModemManager[25850]: <debug> [1506958721.914883]     DNS [0]: 'fd00:976a::9'
ModemManager[25850]: <debug> [1506958721.914896]   MTU: '1500'
ModemManager[25850]: <debug> [1506958721.914947] (wwp0s20u1i6): port now connected
This commit is contained in:
Dan Williams
2017-10-02 10:42:33 -05:00
parent b252ab668f
commit 3e15dc15ef

View File

@@ -304,7 +304,7 @@ ip_configuration_query_ready (MbimDevice *device,
mm_dbg ("IPv4 configuration available: '%s'", str); mm_dbg ("IPv4 configuration available: '%s'", str);
g_free (str); g_free (str);
if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) { if ((ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) && ipv4addresscount) {
guint i; guint i;
mm_dbg (" IP addresses (%u)", ipv4addresscount); mm_dbg (" IP addresses (%u)", ipv4addresscount);
@@ -317,7 +317,7 @@ ip_configuration_query_ready (MbimDevice *device,
} }
} }
if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) { if ((ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) && ipv4gateway) {
addr = g_inet_address_new_from_bytes ((guint8 *)ipv4gateway, G_SOCKET_FAMILY_IPV4); addr = g_inet_address_new_from_bytes ((guint8 *)ipv4gateway, G_SOCKET_FAMILY_IPV4);
str = g_inet_address_to_string (addr); str = g_inet_address_to_string (addr);
mm_dbg (" Gateway: '%s'", str); mm_dbg (" Gateway: '%s'", str);
@@ -325,7 +325,7 @@ ip_configuration_query_ready (MbimDevice *device,
g_object_unref (addr); g_object_unref (addr);
} }
if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) { if ((ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) && ipv4dnsservercount) {
guint i; guint i;
mm_dbg (" DNS addresses (%u)", ipv4dnsservercount); mm_dbg (" DNS addresses (%u)", ipv4dnsservercount);
@@ -340,7 +340,7 @@ ip_configuration_query_ready (MbimDevice *device,
} }
} }
if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) { if ((ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) && ipv4mtu) {
mm_dbg (" MTU: '%u'", ipv4mtu); mm_dbg (" MTU: '%u'", ipv4mtu);
} }
@@ -350,7 +350,7 @@ ip_configuration_query_ready (MbimDevice *device,
mm_dbg ("IPv6 configuration available: '%s'", str); mm_dbg ("IPv6 configuration available: '%s'", str);
g_free (str); g_free (str);
if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) { if ((ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) && ipv6addresscount) {
guint i; guint i;
mm_dbg (" IP addresses (%u)", ipv6addresscount); mm_dbg (" IP addresses (%u)", ipv6addresscount);
@@ -363,7 +363,7 @@ ip_configuration_query_ready (MbimDevice *device,
} }
} }
if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) { if ((ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) && ipv6gateway) {
addr = g_inet_address_new_from_bytes ((guint8 *)ipv6gateway, G_SOCKET_FAMILY_IPV6); addr = g_inet_address_new_from_bytes ((guint8 *)ipv6gateway, G_SOCKET_FAMILY_IPV6);
str = g_inet_address_to_string (addr); str = g_inet_address_to_string (addr);
mm_dbg (" Gateway: '%s'", str); mm_dbg (" Gateway: '%s'", str);
@@ -371,7 +371,7 @@ ip_configuration_query_ready (MbimDevice *device,
g_object_unref (addr); g_object_unref (addr);
} }
if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) { if ((ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_DNS) && ipv6dnsservercount) {
guint i; guint i;
mm_dbg (" DNS addresses (%u)", ipv6dnsservercount); mm_dbg (" DNS addresses (%u)", ipv6dnsservercount);
@@ -386,7 +386,7 @@ ip_configuration_query_ready (MbimDevice *device,
} }
} }
if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) { if ((ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU) && ipv6mtu) {
mm_dbg (" MTU: '%u'", ipv6mtu); mm_dbg (" MTU: '%u'", ipv6mtu);
} }