This patch attempts to fix four bugs in the oscar protocol plugin that
authorMark Doliner <markdoliner@pidgin.im>
Wed, 21 Jul 2010 02:49:23 +0000
changeseta56f371f289a pushlog
parent e820a6573ea0
child a8b26bdf35f2
This patch attempts to fix four bugs in the oscar protocol plugin that
were introduced with the X-Status code in Pidgin 2.7.0.

Problem #1 (the remotely-triggerable crash):
The crash happens when a buddy sets an xstatus message containing <desc>
but no closing </desc>, or <title> but no closing </title>. The fix
is to check the result of strstr(closing_tag_name) and do nothing if it
is NULL. This is CVE-2010-2528.

Problem #2:
Fixes potential incorrect parsing of the xstatus string that could result
in an incorrect message being displayed to the libpurple user. Happens if
an xstatus message contains </desc> before <desc>, or </title> before
<title>. The fix is to start looking for the closing tag at the end
of the beginning tag rather than at the beginning of the xstatus xml.
Probably not a security problem, but definitely a bug.

Problem #3:
Fixes potential incorrect parsing of the xstatus string that could result
in the title not being shown to the libpurple user. Happens if the close
title tag appears after the desc tag in the xstatus xml, because we add a
null character at the beginning of the close title tag, so strstr() for
the desc tag would stop searching there. Probably not a security problem,
but definitely a bug.

Problem #4:
Fixes potential incorrect display of the xstatus string that could result
in an incorrect message being displayed to the libpurple user. Happens
because we reusing the 'xml' string when preparing the string for the user,
but we copy values from xml to xml. If those values overlap with themselves
or with each other then an incorrect value could be displayed. Probably not
a security problem, but definitely a bug.
libpurple/protocols/oscar/family_icbm.c
     1.1 --- a/libpurple/protocols/oscar/family_icbm.c
     1.2 +++ b/libpurple/protocols/oscar/family_icbm.c
     1.3 @@ -249,9 +249,6 @@
     1.4  	}
     1.5  	g_free(buf);
     1.6  
     1.7 -
     1.8 -
     1.9 -
    1.10  	g_free(snac2->data);
    1.11  	g_free(snac2);
    1.12  
    1.13 @@ -2687,7 +2684,6 @@
    1.14  	guint16 hdrlen;
    1.15  	int curpos;
    1.16  	guint16 num1, num2;
    1.17 -	char *desc, *title, *temp;
    1.18  	PurpleAccount *account;
    1.19  	PurpleBuddy *buddy;
    1.20  	PurplePresence *presence;
    1.21 @@ -2714,33 +2710,41 @@
    1.22  				xml = byte_stream_getstr(bs, bs->len - curpos);
    1.23  				purple_debug_misc("oscar", "X-Status: Received XML reply\n");
    1.24  				if (xml) {
    1.25 -				/* purple_debug_misc("oscar", "X-Status: XML reply: %s\n", xml); */
    1.26 -					desc = strstr(xml, "&lt;desc&gt;");
    1.27 -					if (desc != NULL) {
    1.28 -						temp = strstr(xml, "&lt;/desc&gt;");
    1.29 -						temp[0] = 0;
    1.30 -						desc = desc + 12;
    1.31 +					GString *xstatus;
    1.32 +					char *tmp1, *tmp2;
    1.33 +
    1.34 +					/* purple_debug_misc("oscar", "X-Status: XML reply: %s\n", xml); */
    1.35 +
    1.36 +					xstatus = g_string_new(NULL);
    1.37 +
    1.38 +					tmp1 = strstr(xml, "&lt;title&gt;");
    1.39 +					if (tmp1 != NULL) {
    1.40 +						tmp1 += 13;
    1.41 +						tmp2 = strstr(tmp1, "&lt;/title&gt;");
    1.42 +						if (tmp2 != NULL)
    1.43 +							g_string_append_len(xstatus, tmp1, tmp2 - tmp1);
    1.44  					}
    1.45 -					title = strstr(xml, "&lt;title&gt;");
    1.46 -					if (title != NULL) {
    1.47 -						temp = strstr(xml, "&lt;/title&gt;");
    1.48 -						temp[0] = 0;
    1.49 -						title = title + 13;
    1.50 -					} else {
    1.51 -						title = "";
    1.52 +					tmp1 = strstr(xml, "&lt;desc&gt;");
    1.53 +					if (tmp1 != NULL) {
    1.54 +						tmp1 += 12;
    1.55 +						tmp2 = strstr(tmp1, "&lt;/desc&gt;");
    1.56 +						if (tmp2 != NULL) {
    1.57 +							if (xstatus->len > 0)
    1.58 +								g_string_append(xstatus, " - ");
    1.59 +							g_string_append_len(xstatus, tmp1, tmp2 - tmp1);
    1.60 +						}
    1.61  					}
    1.62 -					strcpy(xml,title);
    1.63 -					if (desc) {
    1.64 -						strcat(xml, " - ");
    1.65 -						strcat(xml, desc);
    1.66 +					if (xstatus->len > 0) {
    1.67 +						purple_debug_misc("oscar", "X-Status reply: %s\n", xstatus->str);
    1.68 +						account = purple_connection_get_account(od->gc);
    1.69 +						buddy = purple_find_buddy(account, bn);
    1.70 +						presence = purple_buddy_get_presence(buddy);
    1.71 +						status = purple_presence_get_active_status(presence);
    1.72 +						purple_prpl_got_user_status(account, bn,
    1.73 +								purple_status_get_id(status),
    1.74 +								"message", xstatus->str, NULL);
    1.75  					}
    1.76 -					purple_debug_misc("oscar", "X-Status reply: %s\n", xml);
    1.77 -					account = purple_connection_get_account(od->gc);
    1.78 -					buddy = purple_find_buddy(account, bn);
    1.79 -					presence = purple_buddy_get_presence(buddy);
    1.80 -					status = purple_presence_get_active_status(presence);
    1.81 -					purple_prpl_got_user_status(account, bn,
    1.82 -							purple_status_get_id(status), "message", xml, NULL);
    1.83 +					g_string_free(xstatus, TRUE);
    1.84  				} else {
    1.85  					purple_debug_misc("oscar", "X-Status: Can't get XML reply string\n");
    1.86  				}