dovecot-2.2: quoted-printable decode didn't ignore whitespace at...

dovecot at dovecot.org dovecot at dovecot.org
Fri Aug 10 07:32:20 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/9195486cb5c2
changeset: 14848:9195486cb5c2
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Aug 10 07:31:28 2012 +0300
description:
quoted-printable decode didn't ignore whitespace at the end of soft line break.

diffstat:

 src/lib-mail/quoted-printable.c      |  42 +++++++++++++++++++++++------------
 src/lib-mail/test-quoted-printable.c |   6 ++--
 2 files changed, 30 insertions(+), 18 deletions(-)

diffs (85 lines):

diff -r b3567ec85f9e -r 9195486cb5c2 src/lib-mail/quoted-printable.c
--- a/src/lib-mail/quoted-printable.c	Fri Aug 10 07:01:34 2012 +0300
+++ b/src/lib-mail/quoted-printable.c	Fri Aug 10 07:31:28 2012 +0300
@@ -8,11 +8,31 @@
 #define QP_IS_TRAILING_SPACE(c) \
 	((c) == ' ' || (c) == '\t')
 
+static int
+qp_is_end_of_line(const unsigned char *src, size_t *src_pos, size_t size)
+{
+	size_t i = *src_pos;
+
+	i_assert(src[i] == '=');
+	for (i++; i < size; i++) {
+		if (QP_IS_TRAILING_SPACE(src[i]) || src[i] == '\r')
+			continue;
+
+		if (src[i] != '\n')
+			return 0;
+
+		*src_pos = i;
+		return 1;
+	}
+	return -1;
+}
+
 void quoted_printable_decode(const unsigned char *src, size_t src_size,
 			     size_t *src_pos_r, buffer_t *dest)
 {
 	char hexbuf[3];
 	size_t src_pos, pos, next;
+	int ret;
 
 	hexbuf[2] = '\0';
 
@@ -38,26 +58,18 @@
 		buffer_append(dest, src + next, src_pos - next);
 		next = src_pos;
 
-		if (src_pos+1 >= src_size)
-			break;
-
-		if (src[src_pos+1] == '\n') {
-			/* =\n -> skip both */
-			src_pos++;
-			next += 2;
+		if ((ret = qp_is_end_of_line(src, &src_pos, src_size)) > 0) {
+			/* =[whitespace][\r]\n */
+			next = src_pos+1;
 			continue;
 		}
-
+		if (ret < 0) {
+			/* unknown yet if this is end of line */
+			break;
+		}
 		if (src_pos+2 >= src_size)
 			break;
 
-		if (src[src_pos+1] == '\r' && src[src_pos+2] == '\n') {
-			/* =\r\n -> skip both */
-			src_pos += 2;
-			next += 3;
-			continue;
-		}
-
 		/* =<hex> */
 		hexbuf[0] = src[src_pos+1];
 		hexbuf[1] = src[src_pos+2];
diff -r b3567ec85f9e -r 9195486cb5c2 src/lib-mail/test-quoted-printable.c
--- a/src/lib-mail/test-quoted-printable.c	Fri Aug 10 07:01:34 2012 +0300
+++ b/src/lib-mail/test-quoted-printable.c	Fri Aug 10 07:31:28 2012 +0300
@@ -16,9 +16,9 @@
 {
 	static struct test_quoted_printable_decode_data data[] = {
 		{ "foo  \r\nbar=", "foo\r\nbar", 1 },
-		{ "foo =\nbar", "foo bar", 0 },
-		{ "foo =\n=01", "foo \001", 0 },
-		{ "foo =\r\nbar", "foo bar", 0 },
+		{ "foo\t=\nbar", "foo\tbar", 0 },
+		{ "foo = \n=01", "foo \001", 0 },
+		{ "foo =\t\r\nbar", "foo bar", 0 },
 		{ "foo =\r\n=01", "foo \001", 0 },
 		{ "foo  \nbar=", "foo\r\nbar", 1 },
 		{ "=0A=0D  ", "\n\r", 2 },


More information about the dovecot-cvs mailing list