[evolution-patches] [Contacts] Fix for 317411



Hi,

Attached patch fixes 317411 and other related crashes due to similar
"combination" of characters in the FullName field.

Let me know your comments.

Thanks,

V. Varadhan
Index: addressbook/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/ChangeLog,v
retrieving revision 1.329
diff -u -p -r1.329 ChangeLog
--- addressbook/ChangeLog	30 Nov 2005 13:18:01 -0000	1.329
+++ addressbook/ChangeLog	7 Dec 2005 17:11:37 -0000
@@ -1,3 +1,11 @@
+2005-12-07  Veerapuram Varadhan <vvaradhan novell com>
+
+	* libebook/e-name-western.c: (e_name_western_parse):
+	Check for "screwed-up" random before actually parsing it.
+	(e_name_western_check_screwedup): Check for invalid combination of
+	prefix and comma separation and returns TRUE or FALSE accordingly.
+	** Fixes #317411
+	
 2005-11-30  Harish Krishnaswamy  <kharish novell com>
 
 	* backends/ldap/e-book-backend-ldap.c: (poll_ldap):
Index: addressbook/libebook/e-name-western.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/addressbook/libebook/e-name-western.c,v
retrieving revision 1.3
diff -u -p -r1.3 e-name-western.c
--- addressbook/libebook/e-name-western.c	4 May 2005 08:46:12 -0000	1.3
+++ addressbook/libebook/e-name-western.c	7 Dec 2005 17:11:37 -0000
@@ -608,6 +608,73 @@ e_name_western_detect_backwards (ENameWe
 	return TRUE;
 }
 
+static gboolean
+e_name_western_check_screwedup  (ENameWestern *name, ENameWesternIdxs *idxs)
+{
+	char *comma1;
+	char *comma2;
+	char *prefix1;
+	char *prefix2;
+	char *first;
+	char *last;
+	char *p;
+
+	/* 
+	   Consider this case, "Br. Gate,Br. Gate,W". I know this is a damn
+	   random name, but, I got this from the report of 317411.
+	   
+	   comma1 = ",Br.Gate,W"
+	   comma2 = ",W"
+	   prefix1 = ".Gate,Br.Gate,W"
+	   prefix2 = ". Gate,W"
+	   
+	   When e_name_western_reorder_asshole () is called, comma
+	   (comma1) < p (prefix2) and hence crashes while allocating
+	   memory for "last" variable.
+	   
+	   Actually, we don't have to put lot of intelligence in reordering such
+	   screwedup names, hence this function.
+	*/
+
+	comma1 = g_utf8_strchr (name->full, -1, ',');
+	comma2 = g_utf8_strrchr (name->full, -1, ',');
+	prefix1 = g_utf8_strchr (name->full, -1, '.');
+	prefix2 = g_utf8_strrchr (name->full, -1, '.');
+
+	if (!comma1)
+		return FALSE;
+	
+	/* 
+	   We will try to reorder names of form
+	   "Prefix1 Prefix2 First, MidNickLastSuffix" or
+	   "Prefix1 First, <any-order-of-mid-nick-last-and-suffix>"
+	   but not "Prefix1 Last,Prefix2 First-etc"
+	*/   
+	if (comma1 - prefix2 > 0 &&
+	    (comma1 == comma2 ||
+	     prefix1 == prefix2))
+		return FALSE;
+	/* 
+	   Ok, the name is screwed up.  Parsing is simple, everything before 
+	   comma1 is last name and rest is first name.  We don't need any great
+	   intelligent parser to handle screwed up names.
+	*/
+	p = name->full + strlen (name->full);
+	last = g_malloc0 (comma1 - name->full + 1);
+	strncpy (last, name->full, comma1 - name->full);
+
+	if (comma1 != comma2) {
+		first = g_malloc0 (p - comma1);
+		strncpy (first, comma1+1, p-(comma1+1));		
+		idxs->first_idx = (p - comma1) + 1;
+		name->first = first;
+	}
+	idxs->last_idx = 0;
+	name->last = last;
+
+	return TRUE;
+}
+
 static void
 e_name_western_reorder_asshole (ENameWestern *name, ENameWesternIdxs *idxs)
 {
@@ -929,7 +996,10 @@ e_name_western_parse (const char *full_n
 	idxs->nick_idx   = -1;
 	idxs->last_idx   = -1;
 	idxs->suffix_idx = -1;
-	
+
+	if (e_name_western_check_screwedup  (wname, idxs))
+		goto cleanup;
+
 	/*
 	 * An extremely simple algorithm.
 	 *
@@ -956,6 +1026,7 @@ e_name_western_parse (const char *full_n
 
 	e_name_western_fixup            (wname, idxs);
 
+ cleanup:
 	g_free (idxs);
 
 	return wname;


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