NetworkManager r3307 - in branches/NETWORKMANAGER_0_6_0_RELEASE: . src utils



Author: dcbw
Date: Tue Feb 12 03:03:29 2008
New Revision: 3307
URL: http://svn.gnome.org/viewvc/NetworkManager?rev=3307&view=rev

Log:
2008-02-11  Dan Williams  <dcbw redhat com>

	Fix gnome.org #399292

	* utils/nm-utils.c
	  utils/nm-utils.h
		- (nm_dbus_escape_object_path -> nm_dbus_escape_object_path_item): don't
			pass '/' through, escape it too; therefore the function is no
			longer suitable for escaping entire object paths, but only elements
			of an object path.  Helps fixing crashes due to libdbus assertions
			when trying to push invalid object paths through.

	* src/NetworkManagerDbus.c
		- (nm_dbus_get_object_path_for_device,
		   nm_dbus_get_object_path_for_network,
		   nm_dbus_get_device_from_escaped_object_path,
		   nm_dbus_devices_message_handler): escape individual elements of the
			object path, not the whole path

	* src/nm-dbus-nm.c
		- (nm_dbus_nm_create_test_device): escape individual elements of the
			object path, not the whole path

	* src/nm-dbus-net.c
		- (nm_dbus_get_ap_from_object_path): escape individual elements of the
			object path, not the whole path



Modified:
   branches/NETWORKMANAGER_0_6_0_RELEASE/ChangeLog
   branches/NETWORKMANAGER_0_6_0_RELEASE/src/NetworkManagerDbus.c
   branches/NETWORKMANAGER_0_6_0_RELEASE/src/nm-dbus-net.c
   branches/NETWORKMANAGER_0_6_0_RELEASE/src/nm-dbus-nm.c
   branches/NETWORKMANAGER_0_6_0_RELEASE/utils/nm-utils.c
   branches/NETWORKMANAGER_0_6_0_RELEASE/utils/nm-utils.h

Modified: branches/NETWORKMANAGER_0_6_0_RELEASE/src/NetworkManagerDbus.c
==============================================================================
--- branches/NETWORKMANAGER_0_6_0_RELEASE/src/NetworkManagerDbus.c	(original)
+++ branches/NETWORKMANAGER_0_6_0_RELEASE/src/NetworkManagerDbus.c	Tue Feb 12 03:03:29 2008
@@ -82,15 +82,18 @@
  */
 char * nm_dbus_get_object_path_for_device (NMDevice *dev)
 {
-	char *object_path, *escaped_object_path;
+	char *object_path, *escaped_dev;
 
 	g_return_val_if_fail (dev != NULL, NULL);
 
-	object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
-	escaped_object_path = nm_dbus_escape_object_path (object_path);
-	g_free (object_path);
+	escaped_dev = nm_dbus_escape_object_path_item (nm_device_get_iface (dev));
+	if (!escaped_dev)
+		return NULL;
+
+	object_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, escaped_dev);
+	g_free (escaped_dev);
 
-	return escaped_object_path;
+	return object_path;
 }
 
 
@@ -102,7 +105,7 @@
  */
 char * nm_dbus_get_object_path_for_network (NMDevice *dev, NMAccessPoint *ap)
 {
-	char *object_path, *escaped_object_path;
+	char *object_path = NULL, *escaped_ssid = NULL, *escaped_dev = NULL;
 
 	g_return_val_if_fail (dev != NULL, NULL);
 	g_return_val_if_fail (ap != NULL, NULL);
@@ -110,11 +113,15 @@
 	if (!nm_ap_get_essid (ap))
 		return NULL;
 
-	object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev), nm_ap_get_essid (ap));
-	escaped_object_path = nm_dbus_escape_object_path (object_path);
-	g_free (object_path);
+	escaped_ssid = nm_dbus_escape_object_path_item (nm_ap_get_essid (ap));
+	escaped_dev = nm_dbus_escape_object_path_item (nm_device_get_iface (dev));
+	if (escaped_dev && escaped_ssid)
+		object_path = g_strdup_printf ("%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES, escaped_dev, escaped_ssid);
+
+	g_free (escaped_ssid);
+	g_free (escaped_dev);
 
-	return escaped_object_path;
+	return object_path;
 }
 
 
@@ -139,25 +146,29 @@
 	for (elt = data->dev_list; elt; elt = g_slist_next (elt))
 	{
 		char *compare_path;
-		char *escaped_compare_path;
+		char *escaped_dev;
 		int len;
 
 		if (!(dev = (NMDevice *)(elt->data)))
 			continue;
 
-		compare_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
-		escaped_compare_path = nm_dbus_escape_object_path (compare_path);
-		g_free (compare_path);
-		len = strlen (escaped_compare_path);
+		escaped_dev = nm_dbus_escape_object_path_item (nm_device_get_iface (dev));
+		if (!escaped_dev)
+			continue;
+
+		compare_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, escaped_dev);
+		g_free (escaped_dev);
+
+		len = strlen (compare_path);
 
 		/* Compare against our constructed path, but ignore any trailing elements */
-		if (    (strncmp (path, escaped_compare_path, len) == 0)
+		if (    (strncmp (path, compare_path, len) == 0)
 			&& ((path[len] == '\0' || path[len] == '/')))
 		{
-			g_free (escaped_compare_path);
+			g_free (compare_path);
 			break;
 		}
-		g_free (escaped_compare_path);
+		g_free (compare_path);
 		dev = NULL;
 	}
 	nm_unlock_mutex (data->dev_list_mutex, __FUNCTION__);
@@ -639,21 +650,24 @@
 		reply = nm_dbus_create_error_message (message, NM_DBUS_INTERFACE, "DeviceNotFound", "The requested network device does not exist.");
 	else
 	{
-		char			*object_path, *escaped_object_path;
+		char			*object_path, *escaped_dev;
 		NMDbusCBData	 cb_data;
 
 		cb_data.data = data;
 		cb_data.dev = dev;
 
 		/* Test whether or not the _networks_ of a device were queried instead of the device itself */
-		object_path = g_strdup_printf ("%s/%s/Networks/", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
-		escaped_object_path = nm_dbus_escape_object_path (object_path);
-		g_free (object_path);
-		if (strncmp (path, escaped_object_path, strlen (escaped_object_path)) == 0)
-			handled = nm_dbus_method_dispatch (data->net_methods, connection, message, &cb_data, &reply);
-		else
-			handled = nm_dbus_method_dispatch (data->device_methods, connection, message, &cb_data, &reply);
-		g_free (escaped_object_path);
+		escaped_dev = nm_dbus_escape_object_path_item (nm_device_get_iface (dev));
+		if (escaped_dev) {
+			object_path = g_strdup_printf ("%s/%s/Networks/", NM_DBUS_PATH_DEVICES, escaped_dev);
+			g_free (escaped_dev);
+
+			if (strncmp (path, object_path, strlen (object_path)) == 0)
+				handled = nm_dbus_method_dispatch (data->net_methods, connection, message, &cb_data, &reply);
+			else
+				handled = nm_dbus_method_dispatch (data->device_methods, connection, message, &cb_data, &reply);
+			g_free (object_path);
+		}
 	}
 
 	if (reply)

Modified: branches/NETWORKMANAGER_0_6_0_RELEASE/src/nm-dbus-net.c
==============================================================================
--- branches/NETWORKMANAGER_0_6_0_RELEASE/src/nm-dbus-net.c	(original)
+++ branches/NETWORKMANAGER_0_6_0_RELEASE/src/nm-dbus-net.c	Tue Feb 12 03:03:29 2008
@@ -39,7 +39,6 @@
 	NMAccessPoint		*ap = NULL;
 	NMAccessPointList	*ap_list;
 	NMAPListIter		*iter;
-	char			compare_path[100], *escaped_compare_path;
 
 	g_return_val_if_fail (path != NULL, NULL);
 	g_return_val_if_fail (dev != NULL, NULL);
@@ -51,29 +50,39 @@
 	if (!(iter = nm_ap_list_iter_new (ap_list)))
 		return (NULL);
 
-	while ((ap = nm_ap_list_iter_next (iter)))
-	{
+	while ((ap = nm_ap_list_iter_next (iter))) {
 		int len;
+		char *compare_path, *escaped_dev, *escaped_ssid;
 
-		snprintf (compare_path, 100, "%s/%s/Networks/%s", NM_DBUS_PATH_DEVICES,
-				nm_device_get_iface (dev), nm_ap_get_essid (ap));
-		escaped_compare_path = nm_dbus_escape_object_path (compare_path);
+		if (!nm_ap_get_essid (ap))
+			continue;
 
-		len = strlen(escaped_compare_path);
-		if (strncmp (path, escaped_compare_path, len) == 0)
-		{
+		escaped_dev = nm_dbus_escape_object_path_item (nm_device_get_iface (dev));
+		if (!escaped_dev)
+			continue;
+
+		escaped_ssid = nm_dbus_escape_object_path_item (nm_ap_get_essid (ap));
+		if (!escaped_ssid) {
+			g_free (escaped_dev);
+			continue;
+		}
+
+		compare_path = g_strdup_printf ("%s/%s/Networks/%s",
+		                                NM_DBUS_PATH_DEVICES, escaped_dev, escaped_ssid);
+
+		len = strlen (compare_path);
+		if (strncmp (path, compare_path, len) == 0) {
 			/* Differentiate between 'foo' and 'foo-a' */
-			if (path[len] == '\0' || path[len] == '/')
-			{
-				g_free (escaped_compare_path);
+			if (path[len] == '\0' || path[len] == '/') {
+				g_free (compare_path);
 				break;
 			}
 		}
-		g_free (escaped_compare_path);
+		g_free (compare_path);
 	}
 		
 	nm_ap_list_iter_free (iter);
-	return (ap);
+	return ap;
 }
 
 

Modified: branches/NETWORKMANAGER_0_6_0_RELEASE/src/nm-dbus-nm.c
==============================================================================
--- branches/NETWORKMANAGER_0_6_0_RELEASE/src/nm-dbus-nm.c	(original)
+++ branches/NETWORKMANAGER_0_6_0_RELEASE/src/nm-dbus-nm.c	Tue Feb 12 03:03:29 2008
@@ -434,12 +434,14 @@
 		test_dev_num++;
 		if ((reply = dbus_message_new_method_return (message)))
 		{
-			char		*dev_path, *escaped_dev_path;
-			dev_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, nm_device_get_iface (dev));
-			escaped_dev_path = nm_dbus_escape_object_path (dev_path);
+			char *dev_path, *escaped_dev;
+
+			escaped_dev = nm_dbus_escape_object_path_item (nm_device_get_iface (dev));
+			dev_path = g_strdup_printf ("%s/%s", NM_DBUS_PATH_DEVICES, escaped_dev);
+			g_free (escaped_dev);
+
 			dbus_message_append_args (reply, DBUS_TYPE_STRING, &dev_path, DBUS_TYPE_INVALID);
 			g_free (dev_path);
-			g_free (escaped_dev_path);
 		}
 		g_free (interface);
 		g_free (udi);

Modified: branches/NETWORKMANAGER_0_6_0_RELEASE/utils/nm-utils.c
==============================================================================
--- branches/NETWORKMANAGER_0_6_0_RELEASE/utils/nm-utils.c	(original)
+++ branches/NETWORKMANAGER_0_6_0_RELEASE/utils/nm-utils.c	Tue Feb 12 03:03:29 2008
@@ -27,42 +27,27 @@
 #include <glib.h>
 #include "nm-utils.h"
 
-gchar *nm_dbus_escape_object_path (const gchar *utf8_string)
+gchar *nm_dbus_escape_object_path_item (const gchar *item)
 {
-	const gchar *p;
+	unsigned char *p;
 	gchar *object_path;
 	GString *string;
 
-	g_return_val_if_fail (utf8_string != NULL, NULL);	
-	g_return_val_if_fail (g_utf8_validate (utf8_string, -1, NULL), NULL);
-
-	string = g_string_sized_new ((strlen (utf8_string) + 1) * 6);
-
-	for (p = utf8_string; *p != '\0'; p = g_utf8_next_char (p))
-	{
-		gunichar character;
-
-		character = g_utf8_get_char (p);
+	g_return_val_if_fail (item != NULL, NULL);	
 
-		if (((character >= ((gunichar) 'a')) && 
-		     (character <= ((gunichar) 'z'))) ||
-		    ((character >= ((gunichar) 'A')) && 
-		     (character <= ((gunichar) 'Z'))) ||
-		    ((character >= ((gunichar) '0')) && 
-		     (character <= ((gunichar) '9'))) ||
-		     (character == ((gunichar) '/')))
-		{
-			g_string_append_c (string, (gchar) character);
-			continue;
-		}
+	string = g_string_sized_new ((strlen (item) + 1) * 6);
 
-		g_string_append_printf (string, "_%x_", character);
+	for (p = (unsigned char *) item; *p != '\0'; p++) {
+		if (((*p >= 'a') && (*p <= 'z')) ||
+		    ((*p >= 'A') && (*p <= 'Z')) ||
+		    ((*p >= '0') && (*p <= '9')))
+			g_string_append_c (string, *p);
+		else
+			g_string_append_printf (string, "_%02x_", (unsigned char) *p);
 	}
 
 	object_path = string->str;
-
 	g_string_free (string, FALSE);
-
 	return object_path;
 }
 

Modified: branches/NETWORKMANAGER_0_6_0_RELEASE/utils/nm-utils.h
==============================================================================
--- branches/NETWORKMANAGER_0_6_0_RELEASE/utils/nm-utils.h	(original)
+++ branches/NETWORKMANAGER_0_6_0_RELEASE/utils/nm-utils.h	Tue Feb 12 03:03:29 2008
@@ -125,7 +125,7 @@
 	G_BREAKPOINT ();						\
 } G_STMT_END
 
-gchar *nm_dbus_escape_object_path (const gchar *utf8_string);
+gchar *nm_dbus_escape_object_path_item (const gchar *item);
 gchar *nm_dbus_unescape_object_path (const gchar *object_path);
 
 char *nm_utils_essid_to_utf8 (const char *orig_essid);



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