changeset 29608:8d4bed3021dc

Fix some problems in the oscar code that deals with channel 2 icbms. Specifically related to rtf messages and sent as ICQ server relay. Introduced in 1431506710bed6b8f0c837b670ee314b1692990e in the im.pidgin.cpw.rekkanoryo.icqxstatus branch * memleak fix: We weren't freeing rtfmsg * remote crash fix: We always check args->info.rtfmsg.rtfmsg and try to convert it to UTF-8. However, args->info.rtfmsg is a part of a union and is only set/valid when args->type is OSCAR_CAPABILITY_ICQSERVERRELAY So channel 2 icbms of other types (like chat invites, for example) tend to cause a crash. * possibly printing invalid utf-8: if we could not convert rtfmsg to utf8, and the original rtfmsg failed to validate as utf8, then we tried to write the message to the im window anyway. But that's clearly not a good idea. Really glad I happened to find that remote crash before we released--dealing with security problems is such a pain.
author Mark Doliner <mark@kingant.net>
date Thu, 18 Mar 2010 07:55:17 +0000
parents 59f4012b2b94
children 80933c92c080
files libpurple/protocols/oscar/oscar.c
diffstat 1 files changed, 18 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/oscar/oscar.c	Thu Mar 18 05:47:15 2010 +0000
+++ b/libpurple/protocols/oscar/oscar.c	Thu Mar 18 07:55:17 2010 +0000
@@ -2603,7 +2603,6 @@
 	PurpleAccount *account;
 	PurpleMessageFlags flags = 0;
 	char *message = NULL;
-	char *rtfmsg = NULL;
 
 	g_return_val_if_fail(od != NULL, 0);
 	g_return_val_if_fail(od->gc != NULL, 0);
@@ -2634,20 +2633,6 @@
 		}
 	}
 
-	if (args->info.rtfmsg.rtfmsg != NULL)
-	{
-		if (args->encoding != NULL)
-		{
-			char *encoding = NULL;
-			encoding = oscar_encoding_extract(args->encoding);
-			rtfmsg = oscar_encoding_to_utf8(account, encoding, args->info.rtfmsg.rtfmsg,
-			                                 strlen(args->info.rtfmsg.rtfmsg));
-			g_free(encoding);
-		} else {
-			if (g_utf8_validate(args->info.rtfmsg.rtfmsg, strlen(args->info.rtfmsg.rtfmsg), NULL))
-				rtfmsg = g_strdup(args->info.rtfmsg.rtfmsg);
-		}
-	}
 	if (args->type & OSCAR_CAPABILITY_CHAT)
 	{
 		char *encoding, *utf8name, *tmp;
@@ -2737,23 +2722,27 @@
 				"type %d\n", args->info.rtfmsg.msgtype);
 		purple_debug_info("oscar", "Sending X-Status Reply\n");
 
-		if(args->info.rtfmsg.msgtype == 26)
-			icq_relay_xstatus(od, userinfo->bn, args->cookie);
-		
-		if(args->info.rtfmsg.msgtype == 1)
+		if (args->info.rtfmsg.msgtype == 1)
 		{
-			if(rtfmsg)
+			if (args->info.rtfmsg.rtfmsg != NULL)
 			{
-				serv_got_im(gc, userinfo->bn, rtfmsg, flags,
-				            time(NULL));
+				char *rtfmsg = NULL;
+				if (args->encoding != NULL) {
+					char *encoding = oscar_encoding_extract(args->encoding);
+					rtfmsg = oscar_encoding_to_utf8(account, encoding,
+							args->info.rtfmsg.rtfmsg, strlen(args->info.rtfmsg.rtfmsg));
+					g_free(encoding);
+				} else {
+					if (g_utf8_validate(args->info.rtfmsg.rtfmsg, strlen(args->info.rtfmsg.rtfmsg), NULL))
+						rtfmsg = g_strdup(args->info.rtfmsg.rtfmsg);
+				}
+				if (rtfmsg)
+					serv_got_im(gc, userinfo->bn, rtfmsg, flags, time(NULL));
+				g_free(rtfmsg);
 			}
-			else
-			{
-				serv_got_im(gc, userinfo->bn,
-				            args->info.rtfmsg.rtfmsg, flags,
-				            time(NULL));
-			}
-		}
+		} else if(args->info.rtfmsg.msgtype == 26)
+			icq_relay_xstatus(od, userinfo->bn, args->cookie);
+
 	}
 	else
 	{