/pidgin/main: 46ba9c764edc: Fix handling of multibyte utf-8 char...

Daniel Atallah datallah at pidgin.im
Tue Nov 5 21:53:19 EST 2013


Changeset: 46ba9c764edc479d59572be0776c88f162f671f1
Author:	 Daniel Atallah <datallah at pidgin.im>
Date:	 2013-11-05 21:53 -0500
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/46ba9c764edc

Description:

Fix handling of multibyte utf-8 characters in smiley theme files. Fixes #15756.

diffstat:

 pidgin/gtkthemes.c |  15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diffs (49 lines):

diff --git a/pidgin/gtkthemes.c b/pidgin/gtkthemes.c
--- a/pidgin/gtkthemes.c
+++ b/pidgin/gtkthemes.c
@@ -225,6 +225,7 @@ void pidgin_themes_load_smiley_theme(con
 	FILE *f = g_fopen(file, "r");
 	char buf[256];
 	char *i;
+	gsize line_nbr = 0;
 	struct smiley_theme *theme=NULL;
 	struct smiley_list *list = NULL;
 	GSList *lst = smiley_themes;
@@ -260,6 +261,7 @@ void pidgin_themes_load_smiley_theme(con
 		if (!fgets(buf, sizeof(buf), f)) {
 			break;
 		}
+		line_nbr++;
 
 		if (buf[0] == '#' || buf[0] == '\0')
 			continue;
@@ -271,6 +273,11 @@ void pidgin_themes_load_smiley_theme(con
 				continue;
 		}
 
+		if (! g_utf8_validate(buf, -1, NULL)) {
+			purple_debug_error("gtkthemes", "%s:%d is invalid UTF-8\n", file, line_nbr);
+			continue;
+		}
+
 		i = buf;
 		while (isspace(*i))
 			i++;
@@ -309,10 +316,16 @@ void pidgin_themes_load_smiley_theme(con
 			while  (*i) {
 				char l[64];
 				int li = 0;
+				char *next;
 				while (*i && !isspace(*i) && li < sizeof(l) - 1) {
 					if (*i == '\\' && *(i+1) != '\0')
 						i++;
-					l[li++] = *(i++);
+					next = g_utf8_next_char(i);
+					if ((next - i) > (sizeof(l) - li -1)) {
+						break;
+					}
+					while (i != next)
+						l[li++] = *(i++);
 				}
 				l[li] = 0;
 				if (!sfile) {



More information about the Commits mailing list