changeset 7280:f946af3b0039

[gaim-migrate @ 7859] fix &copy; and &reg; in gtkimhtml fix a potential segfault on jabber committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Thu, 16 Oct 2003 04:17:25 +0000
parents 0d24c94e4fbc
children 0f7dd6715a90
files src/gtkimhtml.c src/protocols/jabber/presence.c
diffstat 2 files changed, 21 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkimhtml.c	Thu Oct 16 03:58:50 2003 +0000
+++ b/src/gtkimhtml.c	Thu Oct 16 04:17:25 2003 +0000
@@ -754,43 +754,45 @@
 
 static gboolean
 gtk_imhtml_is_amp_escape (const gchar *string,
-			  gchar       *replace,
+			  gchar       **replace,
 			  gint        *length)
 {
+	static char buf[3];
 	g_return_val_if_fail (string != NULL, FALSE);
 	g_return_val_if_fail (replace != NULL, FALSE);
 	g_return_val_if_fail (length != NULL, FALSE);
 
 	if (!g_ascii_strncasecmp (string, "&amp;", 5)) {
-		*replace = '&';
+		*replace = "&";
 		*length = 5;
 	} else if (!g_ascii_strncasecmp (string, "&lt;", 4)) {
-		*replace = '<';
+		*replace = "<";
 		*length = 4;
 	} else if (!g_ascii_strncasecmp (string, "&gt;", 4)) {
-		*replace = '>';
+		*replace = ">";
 		*length = 4;
 	} else if (!g_ascii_strncasecmp (string, "&nbsp;", 6)) {
-		*replace = ' ';
+		*replace = " ";
 		*length = 6;
 	} else if (!g_ascii_strncasecmp (string, "&copy;", 6)) {
-		*replace = '©'; /* was: '©' */
+		*replace = "©";
 		*length = 6;
 	} else if (!g_ascii_strncasecmp (string, "&quot;", 6)) {
-		*replace = '\"';
+		*replace = "\"";
 		*length = 6;
 	} else if (!g_ascii_strncasecmp (string, "&reg;", 5)) {
-		*replace = '®'; /* was: '®' */
+		*replace = "®";
 		*length = 5;
 	} else if (!g_ascii_strncasecmp (string, "&apos;", 6)) {
-		*replace = '\'';
+		*replace = "\'";
 		*length = 6;
 	} else if (*(string + 1) == '#') {
 		guint pound = 0;
 		if ((sscanf (string, "&#%u;", &pound) == 1) && pound != 0) {
 			if (*(string + 3 + (gint)log10 (pound)) != ';')
 				return FALSE;
-			*replace = (gchar)pound;
+			g_snprintf(buf, sizeof(buf), "%c", (gchar)pound);
+			*replace = buf;
 			*length = 2;
 			while (isdigit ((gint) string [*length])) (*length)++;
 			if (string [*length] == ';') (*length)++;
@@ -898,7 +900,7 @@
 	gchar *e, *a;
 	gchar *val;
 	gint len;
-	gchar c;
+	gchar *c;
 	GString *ret;
 
 	while (g_ascii_strncasecmp (t, opt, strlen (opt))) {
@@ -935,7 +937,7 @@
 	e = val;
 	while(*e) {
 		if(gtk_imhtml_is_amp_escape(e, &c, &len)) {
-			ret = g_string_append_c(ret, c);
+			ret = g_string_append(ret, c);
 			e += len;
 		} else {
 			ret = g_string_append_c(ret, *e);
@@ -1037,7 +1039,7 @@
 	gint tlen, smilelen, wpos=0;
 	gint type;
 	const gchar *c;
-	gchar amp;
+	gchar *amp;
 
 	guint	bold = 0,
 		italics = 0,
@@ -1347,7 +1349,9 @@
 			if(tag)
 				g_free(tag); /* This was allocated back in VALID_TAG() */
 		} else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
-			ws [wpos++] = amp;
+			while(*amp) {
+				ws [wpos++] = *amp++;
+			}
 			c += tlen;
 			pos += tlen;
 		} else if (*c == '\n') {
--- a/src/protocols/jabber/presence.c	Thu Oct 16 03:58:50 2003 +0000
+++ b/src/protocols/jabber/presence.c	Thu Oct 16 04:17:25 2003 +0000
@@ -154,6 +154,9 @@
 
 	jb = jabber_buddy_find(js, from, TRUE);
 
+	if(!jb)
+		return;
+
 	if(jb->error_msg) {
 		g_free(jb->error_msg);
 		jb->error_msg = NULL;