changeset 11176:6932df31225f

[gaim-migrate @ 13283] Fix a buglet in auto linkifying mailto: things, which was causing the MSN prpl to have kittens trying to parse what was being sent. Also fixup the MSN parsing code to be more accomodating in what it accepts from the core - as this code was originally borrowed from the Zephyr prpl, robustify Zephyr in a similar way. Unfortunately I have no way of testing the Zephyr fixes. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 31 Jul 2005 15:21:31 +0000
parents 57af14280b5f
children 3924db2b1ca8
files src/protocols/msn/utils.c src/protocols/zephyr/zephyr.c src/util.c
diffstat 3 files changed, 40 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/msn/utils.c	Sat Jul 30 17:05:38 2005 +0000
+++ b/src/protocols/msn/utils.c	Sun Jul 31 15:21:31 2005 +0000
@@ -221,22 +221,24 @@
 				if (!g_ascii_strncasecmp(c, "mailto:", 7))
 					c += 7;
 
-				while (g_ascii_strncasecmp(c, "\">", 2))
+				while ((*c != '\0') && g_ascii_strncasecmp(c, "\">", 2))
 					msg[retcount++] = *c++;
 
-				c += 2;
+				if (*c != '\0')
+					c += 2;
 
 				/* ignore descriptive string */
-				while (g_ascii_strncasecmp(c, "</a>", 4))
+				while ((*c != '\0') && g_ascii_strncasecmp(c, "</a>", 4))
 					c++;
 
-				c += 4;
+				if (*c != '\0')
+					c += 4;
 			}
 			else if (!g_ascii_strncasecmp(c + 1, "font", 4))
 			{
 				c += 5;
 
-				while (!g_ascii_strncasecmp(c, " ", 1))
+				while ((*c != '\0') && !g_ascii_strncasecmp(c, " ", 1))
 					c++;
 
 				if (!g_ascii_strncasecmp(c, "color=\"#", 7))
@@ -273,18 +275,19 @@
 				else
 				{
 					/* Drop all unrecognized/misparsed font tags */
-					while (g_ascii_strncasecmp(c, "\">", 2))
+					while ((*c != '\0') && g_ascii_strncasecmp(c, "\">", 2))
 						c++;
 
-					c += 2;
+					if (*c != '\0')
+						c += 2;
 				}
 			}
 			else
 			{
-				while (g_ascii_strncasecmp(c, ">", 1))
+				while ((*c != '\0') && (*c != '>'))
 					c++;
-
-				c++;
+				if (*c != '\0')
+					c++;
 			}
 		}
 		else if (*c == '&')
--- a/src/protocols/zephyr/zephyr.c	Sat Jul 30 17:05:38 2005 +0000
+++ b/src/protocols/zephyr/zephyr.c	Sun Jul 31 15:21:31 2005 +0000
@@ -383,58 +383,64 @@
 				retcount += 1;
 			} else if (!g_ascii_strncasecmp(message + cnt + 1, "a href=\"mailto:", 15)) {
 				cnt += 16;
-				while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
+				while ((message[cnt] != '\0') && g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
 					ret[retcount] = message[cnt];
 					retcount++;
 					cnt++;
 				}
-				cnt += 2;
+				if (message[cnt] != '\0')
+					cnt += 2;
 				/* ignore descriptive string */
-				while (g_ascii_strncasecmp(message + cnt, "</a>", 4) != 0) {
+				while ((message[cnt] != '\0') && g_ascii_strncasecmp(message + cnt, "</a>", 4) != 0) {
 					cnt++;
 				}
-				cnt += 4;
+				if (message[cnt] != '\0')
+					cnt += 4;
 			} else if (!g_ascii_strncasecmp(message + cnt + 1, "a href=\"", 8)) {
 				cnt += 9;
-				while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
+				while ((message[cnt] != '\0') && g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
 					ret[retcount] = message[cnt];
 					retcount++;
 					cnt++;
 				}
-				cnt += 2;
+				if (message[cnt] != '\0')
+					cnt += 2;
 				/* ignore descriptive string */
-				while (g_ascii_strncasecmp(message + cnt, "</a>", 4) != 0) {
+				while ((message[cnt] != '\0') && g_ascii_strncasecmp(message + cnt, "</a>", 4) != 0) {
 					cnt++;
 				}
-				cnt += 4;
+				if (message[cnt] != '\0')
+					cnt += 4;
 			} else if (!g_ascii_strncasecmp(message + cnt + 1, "font", 4)) {
 				cnt += 5;
-				while (!g_ascii_strncasecmp(message + cnt, " ", 1))
+				while ((message[cnt] != '\0') && (message[cnt] != ' '))
 					cnt++;
-				if (!g_ascii_strncasecmp(message + cnt, "color=\"", 7)) {
+				if ((message[cnt] != '\0') && !g_ascii_strncasecmp(message + cnt, "color=\"", 7)) {
 					cnt += 7;
 					strncpy(ret + retcount, "@color(", 7);
 					retcount += 7;
-					while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
+					while ((message[cnt] != '\0') && g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
 						ret[retcount] = message[cnt];
 						retcount++;
 						cnt++;
 					}
 					ret[retcount] = ')';
 					retcount++;
-					cnt += 2;
+					if (message[cnt] != '\0')
+						cnt += 2;
 				} else if (!g_ascii_strncasecmp(message + cnt, "face=\"", 6)) {
 					cnt += 6;
 					strncpy(ret + retcount, "@font(", 6);
 					retcount += 6;
-					while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
+					while ((message[cnt] != '\0') && g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
 						ret[retcount] = message[cnt];
 						retcount++;
 						cnt++;
 					}
 					ret[retcount] = ')';
 					retcount++;
-					cnt += 2;
+					if (message[cnt] != '\0')
+						cnt += 2;
 				} else if (!g_ascii_strncasecmp(message + cnt, "size=\"", 6)) {
 					cnt += 6;
 					if ((message[cnt] == '1') || (message[cnt] == '2')) {
@@ -453,10 +459,11 @@
 					cnt += 3;
 				} else {
 					/* Drop all unrecognized/misparsed font tags */
-					while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
+					while ((message[cnt] != '\0') && g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) {
 						cnt++;
 					}
-					cnt += 2;
+					if (message[cnt] != '\0')
+						cnt += 2;
 				}
 			} else if (!g_ascii_strncasecmp(message + cnt + 1, "/i>", 3)
 				   || !g_ascii_strncasecmp(message + cnt + 1, "/b>", 3)) {
@@ -469,7 +476,7 @@
 				retcount += 12;
 			} else {
 				/* Catch all for all unrecognized/misparsed <foo> tage */
-				while (g_ascii_strncasecmp(message + cnt, ">", 1) != 0) {
+				while ((message[cnt] != '\0') && (message[cnt] != '>')) {
 					ret[retcount] = message[cnt];
 					retcount++;
 					cnt++;
--- a/src/util.c	Sat Jul 30 17:05:38 2005 +0000
+++ b/src/util.c	Sun Jul 31 15:21:31 2005 +0000
@@ -1619,7 +1619,9 @@
 				/* iterate backwards grabbing the local part of an email address */
 				g = g_utf8_get_char(t);
 				if (badchar(*t) || (g >= 127) || (*t == '(') ||
-						((*t == ';') && (t > (text+2)) && !g_ascii_strncasecmp(t - 3, "&lt;", 4))) {
+					((*t == ';') && ((t > (text+2) && (!g_ascii_strncasecmp(t - 3, "&lt;", 4) ||
+				                                       !g_ascii_strncasecmp(t - 3, "&gt;", 4))) ||
+				                     (t > (text+4) && (!g_ascii_strncasecmp(t - 5, "&quot;", 6)))))) {
 					/* local part will already be part of ret, strip it out */
 					ret = g_string_truncate(ret, ret->len - (c - t));
 					ret = g_string_append_unichar(ret, g);