[PATCH] dns: store priv->last_iface even when no actual updates are performed



Hi,

the attached patch fixes a segmentation fault with n-m >= 0.9.6.4 (I
upgraded from 0.9.4.0, so it might be introduced earlier).

Here is the commit message:

dns: store priv->last_iface even when no actual updates are performed

Otherwise, with DNS batch updating (commit f76aa4f), we might end up in
the situation where priv->last_iface is NULL when adding a link-local
IPv6 DNS server (e.g. fe80::4e60:deff:fed8:d7c5%wlan0), leading to a
segmentation fault.

-- 
Best regards,
Michael
>From 48d5f34f709dbf00ea0bffeabb4e5db136500a32 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael stapelberg de>
Date: Tue, 5 Feb 2013 19:02:12 +0100
Subject: [PATCH] dns: store priv->last_iface even when no actual updates are
 performed

Otherwise, with DNS batch updating (commit f76aa4f), we might end up in
the situation where priv->last_iface is NULL when adding a link-local
IPv6 DNS server (e.g. fe80::4e60:deff:fed8:d7c5%wlan0), leading to a
segmentation fault.
---
 src/dns-manager/nm-dns-manager.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c
index 38691f3..3bab4cb 100644
--- a/src/dns-manager/nm-dns-manager.c
+++ b/src/dns-manager/nm-dns-manager.c
@@ -91,6 +91,15 @@ typedef struct {
 } NMResolvConfData;
 
 static void
+update_last_iface (NMDnsManagerPrivate *priv, const char *iface)
+{
+	if (iface && (iface != priv->last_iface)) {
+		g_free (priv->last_iface);
+		priv->last_iface = g_strdup (iface);
+	}
+}
+
+static void
 add_string_item (GPtrArray *array, const char *str)
 {
 	int i;
@@ -821,6 +830,7 @@ nm_dns_manager_add_ip4_config (NMDnsManager *mgr,
 	if (!g_slist_find (priv->configs, config))
 		priv->configs = g_slist_append (priv->configs, g_object_ref (config));
 
+	update_last_iface(priv, iface);
 	if (!priv->updates_queue && !update_dns (mgr, iface, FALSE, &error)) {
 		nm_log_warn (LOGD_DNS, "could not commit DNS changes: (%d) %s",
 		             error ? error->code : -1,
@@ -858,6 +868,7 @@ nm_dns_manager_remove_ip4_config (NMDnsManager *mgr,
 
 	g_object_unref (config);
 
+	update_last_iface(priv, iface);
 	if (!priv->updates_queue && !update_dns (mgr, iface, FALSE, &error)) {
 		nm_log_warn (LOGD_DNS, "could not commit DNS changes: (%d) %s",
 		             error ? error->code : -1,
@@ -898,6 +909,7 @@ nm_dns_manager_add_ip6_config (NMDnsManager *mgr,
 	if (!g_slist_find (priv->configs, config))
 		priv->configs = g_slist_append (priv->configs, g_object_ref (config));
 
+	update_last_iface(priv, iface);
 	if (!priv->updates_queue && !update_dns (mgr, iface, FALSE, &error)) {
 		nm_log_warn (LOGD_DNS, "could not commit DNS changes: (%d) %s",
 		             error ? error->code : -1,
@@ -935,6 +947,7 @@ nm_dns_manager_remove_ip6_config (NMDnsManager *mgr,
 
 	g_object_unref (config);	
 
+	update_last_iface(priv, iface);
 	if (!priv->updates_queue && !update_dns (mgr, iface, FALSE, &error)) {
 		nm_log_warn (LOGD_DNS, "could not commit DNS changes: (%d) %s",
 		             error ? error->code : -1,
-- 
1.7.10.4




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]