[evolution-data-server] Bug 662643 - camel_url_decode_path() crashes on empty string



commit 230e8393cd91252bc3f1f25b123a96e7a6f4829a
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Oct 24 17:51:10 2011 -0400

    Bug 662643 - camel_url_decode_path() crashes on empty string

 camel/camel-url.c |   28 +++++++++++++---------------
 1 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/camel/camel-url.c b/camel/camel-url.c
index 7341a74..2e6c98c 100644
--- a/camel/camel-url.c
+++ b/camel/camel-url.c
@@ -794,28 +794,26 @@ gchar *
 camel_url_decode_path (const gchar *path)
 {
 	gchar **comps;
-	gchar *new_path = NULL;
 	GString *str;
-	gint i = 0;
+	guint length, ii;
 
-	if (!path)
-                return g_strdup("");    /* ??? or NULL? */
+	if (path == NULL || *path == '\0')
+		return g_strdup ("");    /* ??? or NULL? */
 
 	str = g_string_new (NULL);
 
-        comps = g_strsplit (path, "/", -1);
-	while (comps[i]) {
-		camel_url_decode (comps[i]);
-		g_string_append (str, comps[i]);
-		g_string_append_c (str, '/');
-		i++;
-	}
+	comps = g_strsplit (path, "/", -1);
+	length = g_strv_length (comps);
 
-        /* Strip-off the trailing "/" */
-	new_path = g_strndup (str->str, str->len - 1);
+	for (ii = 0; ii < length; ii++) {
+		if (ii > 0)
+			g_string_append_c (str, '/');
+		camel_url_decode (comps[ii]);
+		g_string_append (str, comps[ii]);
+	}
 
 	g_strfreev (comps);
-	g_string_free (str, TRUE);
 
-	return new_path;
+	return g_string_free (str, FALSE);
 }
+



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