changeset 30973:79c438f2cb69

Correct parsing of multipart messages in purple_mim_document_parse, when the boundary contains a '='. Fixes #11598. committer: Elliott Sales de Andrade <qulogic@pidgin.im>
author jakub.adam@ktknet.cz
date Sun, 28 Nov 2010 00:44:35 +0000
parents a42f7d3ad459
children f26e961e1274
files ChangeLog libpurple/mime.c
diffstat 2 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Nov 28 00:18:31 2010 +0000
+++ b/ChangeLog	Sun Nov 28 00:44:35 2010 +0000
@@ -5,6 +5,10 @@
 	* Fix the exceptions in purple-remote on Python 2.6+. (Ari Pollak)
 	  (#12151)
 
+	libpurple:
+	* Fix multipart parsing when '=' is included in the boundary for
+	  purple_mime_document_parse. (Jakub Adam) (#11598)
+
 	Gadu-Gadu:
 	* Updated our bundled libgadu and minimum requirement for external
 	  libgadu to 1.9.0. (#12789)
--- a/libpurple/mime.c	Sun Nov 28 00:18:31 2010 +0000
+++ b/libpurple/mime.c	Sun Nov 28 00:44:35 2010 +0000
@@ -436,6 +436,34 @@
 	g_free(bnd);
 }
 
+#define BOUNDARY "boundary="
+static char *
+parse_boundary(const char *ct)
+{
+	char *boundary_begin = g_strstr_len(ct, -1, BOUNDARY);
+	char *boundary_end;
+
+	if (!boundary_begin)
+		return NULL;
+
+	boundary_begin += sizeof(BOUNDARY) - 1;
+
+	if (*boundary_begin == '"') {
+		boundary_end = strchr(++boundary_begin, '"');
+		if (!boundary_end)
+			return NULL;
+	} else {
+		boundary_end = strchr(boundary_begin, ' ');
+		if (!boundary_end) {
+			boundary_end = strchr(boundary_begin, ';');
+			if (!boundary_end)
+				boundary_end = boundary_begin + strlen(boundary_begin);
+		}
+	}
+
+	return g_strndup(boundary_begin, boundary_end - boundary_begin);
+}
+#undef BOUNDARY
 
 PurpleMimeDocument *
 purple_mime_document_parsen(const char *buf, gsize len)
@@ -456,10 +484,11 @@
 
 	{
 		const char *ct = fields_get(&doc->fields, "content-type");
-		if(ct && purple_str_has_prefix(ct, "multipart")) {
-			char *bd = strrchr(ct, '=');
-			if(bd++) {
+		if (ct && purple_str_has_prefix(ct, "multipart")) {
+			char *bd = parse_boundary(ct);
+			if (bd) {
 				doc_parts_load(doc, bd, b, n);
+				g_free(bd);
 			}
 		}
 	}