Fix for an small memory issue



Hi,

this patch fixes an small memory issue detected by valgrind when trying
to parse addresses like "<somebody something com>".

The error report:
==29209== Invalid read of size 1
==29209==    at 0x4100BE3: _string_to_camel_inet_addr
(tny-camel-common.c:268)
==29209==    by 0x4100CCE: _foreach_email_add_to_inet_addr
(tny-camel-common.c:304)
==29209==    by 0x4102BCC: tny_camel_msg_header_set_replyto
(tny-camel-msg-header.c:196)
==29209==    by 0x413D7DC: tny_header_set_replyto (tny-header.c:57)
==29209==    by 0x80854AC: modest_tny_msg_new (modest-tny-msg.c:75)
==29209==    by 0x808ADA0: modest_ui_actions_compose_msg
(modest-ui-actions.c:750)
==29209==    by 0x808AF8D: modest_ui_actions_on_new_msg
(modest-ui-actions.c:788)

==29209==  Address 0x9b6525f is 1 bytes before a block of size 15 alloc'd
==29209==    at 0x40207C4: malloc (vg_replace_malloc.c:207)
==29209==    by 0x4C31E9C: g_malloc (in
/targets/CHINOOK_X86/usr/lib/libglib-2.0.so.0.1200.12)
==29209==    by 0x4C43428: g_strdup (in
/targets/CHINOOK_X86/usr/lib/libglib-2.0.so.0.1200.12)
==29209==    by 0x4100AC9: split_recipients (tny-camel-common.c:233)
==29209==    by 0x4100CA9: _foreach_email_add_to_inet_addr
(tny-camel-common.c:298)
==29209==    by 0x4102BCC: tny_camel_msg_header_set_replyto
(tny-camel-msg-header.c:196)
==29209==    by 0x413D7DC: tny_header_set_replyto (tny-header.c:57)
==29209==    by 0x80854AC: modest_tny_msg_new (modest-tny-msg.c:75)
==29209==    by 0x808ADA0: modest_ui_actions_compose_msg
(modest-ui-actions.c:750)
==29209==    by 0x808AF8D: modest_ui_actions_on_new_msg
(modest-ui-actions.c:788)

Br
Index: libtinymail-camel/tny-camel-common.c
===================================================================
--- libtinymail-camel/tny-camel-common.c	(revision 3547)
+++ libtinymail-camel/tny-camel-common.c	(working copy)
@@ -249,7 +249,8 @@
 		char *name = (char*)tok, *lname = NULL;
 		char *email = stfnd+1, *gtfnd = NULL;
 
-		lname = stfnd-1;
+		if (stfnd != tok)
+			lname = stfnd-1;
 
 		gtfnd = strchr (stfnd, '>');
 	
@@ -265,7 +266,7 @@
 		if (G_LIKELY (*name == ' '))
 			name++;
 	
-		if (G_LIKELY (*lname == ' '))
+		if (G_LIKELY (lname && *lname == ' '))
 			*lname-- = '\0';
 		remove_quotes (name);
 		camel_internet_address_add (target, name, email);


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