From 034e022c01d625f0cd9fac7aaa96eee980f1cb3e Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Wed, 26 Jan 2011 09:22:06 +0100 Subject: [PATCH] provider: Handle empty nameservers If the VPN server doesn't set any DNS entries provider->nameservers is NULL. When we change the state of the provider to CONNMAN_PROVIDER_STATE_READY we shouldn't do any string operations on the NULL pointer namerservers. (gdb) bt full No symbol table info available. type = CONNMAN_ELEMENT_TYPE_IPV4 nameservers = 0x0 value = 0x0 list = 0x1 = { err = 0 element = 0x6a5110 name = 0x6a5550 "vpn0" second_ns = 0x69f1c0 "\004" service = 0x6a2630 No locals. Fixes BMC#12508 Reported by Jeff Zheng --- src/provider.c | 57 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/provider.c b/src/provider.c index 53b3ddd..b47b6b9 100644 --- a/src/provider.c +++ b/src/provider.c @@ -254,6 +254,38 @@ int __connman_provider_remove(const char *path) return -ENXIO; } +static void provider_set_nameservers(struct connman_provider *provider) +{ + char *nameservers = NULL, *name = NULL; + const char *value; + char *second_ns; + + if (provider->dns == NULL) + return; + + name = connman_inet_ifname(provider->element.index); + + nameservers = g_strdup(provider->dns); + value = nameservers; + second_ns = strchr(value, ' '); + if (second_ns) + *(second_ns++) = 0; + __connman_service_append_nameserver(service, value); + value = second_ns; + + while (value) { + char *next = strchr(value, ' '); + if (next) + *(next++) = 0; + + connman_resolver_append(name, provider->domain, value); + value = next; + } + + g_free(nameservers); + g_free(name); +} + static int set_connected(struct connman_provider *provider, connman_bool_t connected) { @@ -265,9 +297,6 @@ static int set_connected(struct connman_provider *provider, if (connected == TRUE) { enum connman_element_type type = CONNMAN_ELEMENT_TYPE_UNKNOWN; struct connman_element *element; - char *nameservers = NULL, *name = NULL; - const char *value; - char *second_ns; GSList *list; int err; @@ -298,27 +327,7 @@ static int set_connected(struct connman_provider *provider, __connman_service_set_domainname(service, provider->domain); - name = connman_inet_ifname(provider->element.index); - - nameservers = g_strdup(provider->dns); - value = nameservers; - second_ns = strchr(value, ' '); - if (second_ns) - *(second_ns++) = 0; - __connman_service_append_nameserver(service, value); - value = second_ns; - - while (value) { - char *next = strchr(value, ' '); - if (next) - *(next++) = 0; - - connman_resolver_append(name, provider->domain, value); - value = next; - } - - g_free(nameservers); - g_free(name); + provider_set_nameservers(provider); for (list = provider->route_list; list; list = list->next) { struct connman_route *route = list->data; -- 2.7.4