Check for add_gateway() return value before dereferencing it
authorSamuel Ortiz <sameo@linux.intel.com>
Mon, 12 Jul 2010 18:40:02 +0000 (20:40 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Mon, 12 Jul 2010 18:44:32 +0000 (20:44 +0200)
add_gateway() also returns NULL for zero length strings.

src/connection.c

index dcaa8fe..5f31885 100644 (file)
@@ -23,6 +23,7 @@
 #include <config.h>
 #endif
 
+#include <string.h>
 #include <net/if.h>
 
 #include <gdbus.h>
@@ -101,6 +102,9 @@ static struct gateway_data *add_gateway(int index, const char *gateway)
        struct gateway_data *data;
        struct connman_service *service;
 
+       if (strlen(gateway) == 0)
+               return NULL;
+
        data = g_try_new0(struct gateway_data, 1);
        if (data == NULL)
                return NULL;
@@ -278,14 +282,15 @@ static int connection_probe(struct connman_element *element)
 
        active_gateway = find_active_gateway();
        new_gateway = add_gateway(element->index, gateway);
+       if (new_gateway == NULL)
+               return 0;
+
        service = __connman_element_get_service(element);
 
-       if (new_gateway) {
-               connman_inet_add_host_route(element->index,
-                                               new_gateway->gateway, NULL);
-               __connman_service_nameserver_add_routes(service,
-                                                       new_gateway->gateway);
-       }
+       connman_inet_add_host_route(element->index,
+                                       new_gateway->gateway, NULL);
+       __connman_service_nameserver_add_routes(service,
+                                               new_gateway->gateway);
 
        __connman_service_indicate_state(service, CONNMAN_SERVICE_STATE_READY);