From: Samuel Ortiz Date: Mon, 12 Jul 2010 18:40:02 +0000 (+0200) Subject: Check for add_gateway() return value before dereferencing it X-Git-Tag: 2.0_alpha~2661 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4dfe58506284f87110393bb3c01bd37bed90e049;p=framework%2Fconnectivity%2Fconnman.git Check for add_gateway() return value before dereferencing it add_gateway() also returns NULL for zero length strings. --- diff --git a/src/connection.c b/src/connection.c index dcaa8fe..5f31885 100644 --- a/src/connection.c +++ b/src/connection.c @@ -23,6 +23,7 @@ #include #endif +#include #include #include @@ -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);