[PATCH 4/4] openconnect: Domain pointer was used incorrectly

Jukka Rissanen jukka.rissanen at linux.intel.com
Fri Nov 2 01:50:31 PDT 2012


We must allocate the domain name from the heap and not
point to it directly because the dbus library will deallocate
it and we will have invalid memory access.
---
 vpn/plugins/openconnect.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/vpn/plugins/openconnect.c b/vpn/plugins/openconnect.c
index fa08779..812908c 100644
--- a/vpn/plugins/openconnect.c
+++ b/vpn/plugins/openconnect.c
@@ -56,7 +56,7 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
 {
 	DBusMessageIter iter, dict;
 	const char *reason, *key, *value;
-	const char *domain = NULL;
+	char *domain = NULL;
 	char *addressv4 = NULL, *addressv6 = NULL;
 	char *netmask = NULL, *gateway = NULL;
 	unsigned char prefix_len = 0;
@@ -75,7 +75,7 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
 	if (strcmp(reason, "connect"))
 		return VPN_STATE_DISCONNECT;
 
-	domain = vpn_provider_get_string(provider, "VPN.Domain");
+	domain = g_strdup(vpn_provider_get_string(provider, "VPN.Domain"));
 
 	dbus_message_iter_recurse(&iter, &dict);
 
@@ -125,8 +125,10 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
 		if (!strcmp(key, "CISCO_PROXY_PAC"))
 			vpn_provider_set_pac(provider, value);
 
-		if (domain == NULL && !strcmp(key, "CISCO_DEF_DOMAIN"))
-			domain = value;
+		if (domain == NULL && !strcmp(key, "CISCO_DEF_DOMAIN")) {
+			g_free(domain);
+			domain = g_strdup(value);
+		}
 
 		if (g_str_has_prefix(key, "CISCO_SPLIT_INC") == TRUE ||
 			g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC") == TRUE)
@@ -149,6 +151,7 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
 		g_free(addressv6);
 		g_free(netmask);
 		g_free(gateway);
+		g_free(domain);
 
 		return VPN_STATE_FAILURE;
 	}
@@ -166,6 +169,7 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
 	g_free(addressv6);
 	g_free(netmask);
 	g_free(gateway);
+	g_free(domain);
 	connman_ipaddress_free(ipaddress);
 
 	return VPN_STATE_CONNECT;
-- 
1.7.11.4




More information about the connman mailing list