pidgin: 3a43fb06: Correct parsing of multipart messages in...

qulogic at pidgin.im qulogic at pidgin.im
Sun Nov 28 03:25:04 EST 2010


----------------------------------------------------------------------
Revision: 3a43fb06bb25d5b2835f6a1f60e9543396b4c457
Parent:   cb89d88037865aa2ec058f28dc480e92825cd9f5
Author:   jakub.adam at ktknet.cz
Date:     11/27/10 19:44:35
Branch:   im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/3a43fb06bb25d5b2835f6a1f60e9543396b4c457

Changelog: 

Correct parsing of multipart messages in purple_mim_document_parse,
when the boundary contains a '='.

Fixes #11598.

Changes against parent cb89d88037865aa2ec058f28dc480e92825cd9f5

  patched  ChangeLog
  patched  libpurple/mime.c

-------------- next part --------------
============================================================
--- ChangeLog	dd128f7d1bb7f75a5096590665e2c614d9bee8e6
+++ ChangeLog	a81b7045951168a42519f5c2cb4fdc928d4ad61c
@@ -5,6 +5,10 @@ version 2.7.8 (??/??/????):
 	* 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)
============================================================
--- libpurple/mime.c	087654f8fa87af0d3cfed7e480baa1a0299400a8
+++ libpurple/mime.c	94769a59a76e8b77da117959d487d89230fd6e74
@@ -436,7 +436,35 @@ doc_parts_load(PurpleMimeDocument *doc, 
 	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 @@ purple_mime_document_parsen(const char *
 
 	{
 		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);
 			}
 		}
 	}


More information about the Commits mailing list