pidgin: c18f0b93: Fix some problems in the oscar code that...

markdoliner at pidgin.im markdoliner at pidgin.im
Thu Mar 18 04:02:06 EDT 2010


-----------------------------------------------------------------
Revision: c18f0b937508a4838b418093b46adc70bdded382
Ancestor: 4daa81110f07fded726a9c4bcbbc75862aa60edb
Author: markdoliner at pidgin.im
Date: 2010-03-18T07:55:17
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/c18f0b937508a4838b418093b46adc70bdded382

Modified files:
        libpurple/protocols/oscar/oscar.c

ChangeLog: 

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.

-------------- next part --------------
============================================================
--- libpurple/protocols/oscar/oscar.c	4d3709a1f00de21f477ab58426c87ecd046bfbad
+++ libpurple/protocols/oscar/oscar.c	2ab15092dae721866c4dbff11488fa3a93b79980
@@ -2603,7 +2603,6 @@ incomingim_chan2(OscarData *od, FlapConn
 	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 @@ incomingim_chan2(OscarData *od, FlapConn
 		}
 	}
 
-	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 @@ incomingim_chan2(OscarData *od, FlapConn
 				"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
 	{


More information about the Commits mailing list