Add checks for networks if attribute is not available
authorSamuel Ortiz <sameo@linux.intel.com>
Tue, 7 Jul 2009 16:02:27 +0000 (18:02 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 7 Jul 2009 17:26:54 +0000 (10:26 -0700)
We do actually want to check for NULL pointers, not to prevent g_strcmp0
from crashing, but because we want to compare the 2 pointers when we've
been given one and the network we're looking at has a pointer too.

For example if we call find_network() without an address, it basically
means "find a network with an SSID, and with _any_ address". But then
we're going to compare a NULL pointer with the network's address and
that's gonna be -1. As a consequence, we'll skip this network while
we shouldnt.

src/device.c

index aa53304..ec28eb0 100644 (file)
@@ -512,13 +512,15 @@ static struct connman_network *find_network(struct connman_device *device,
                if (tmp_ssid && memcmp(ssid, tmp_ssid, tmp_ssid_size))
                        continue;
 
-               if (g_strcmp0(security, tmp_security) != 0)
+               if (security && tmp_security &&
+                               g_strcmp0(security, tmp_security) != 0)
                        continue;
 
-               if (g_strcmp0(mode, tmp_mode) != 0)
+               if (mode && tmp_mode && g_strcmp0(mode, tmp_mode) != 0)
                        continue;
 
-               if (g_strcmp0(address, tmp_address) != 0)
+               if (address && tmp_address &&
+                               g_strcmp0(address, tmp_address) != 0)
                        continue;
 
                return connman_network_ref(value);