[PATCH v0] provider: Handle empty nameservers

Daniel Wagner wagi at monom.org
Wed Jan 26 00:22:06 PST 2011


From: Daniel Wagner <daniel.wagner at bmw-carit.de>

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
#0  0x00000039ee88124a in __strchr_sse2 () from /lib64/libc.so.6
No symbol table info available.
#1  0x000000000044cca2 in set_connected (provider=0x69f1c0, connected=1) at src/provider.c:305
        type = CONNMAN_ELEMENT_TYPE_IPV4
        nameservers = 0x0
        value = 0x0
        list = 0x1 = {<error reading variable list (Cannot access memory at address 0x1)>
        err = 0
        element = 0x6a5110
        name = 0x6a5550 "vpn0"
        second_ns = 0x69f1c0 "\004"
        service = 0x6a2630
#2  0x000000000044ce56 in connman_provider_set_state (provider=0x69f1c0, state=CONNMAN_PROVIDER_STATE_READY) at src/provider.c:356
No locals.

This a bug fix for #12508

Reported by Jeff Zheng <jeff.zheng at intel.com>
---
 src/provider.c |   57 ++++++++++++++++++++++++++++++++-----------------------
 1 files 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;
-- 
1.7.3.5




More information about the connman mailing list