]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message-header-encode - Fix encoding of 0x7F byte for Q encoding.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 16 Sep 2020 23:33:52 +0000 (01:33 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 7 Oct 2020 14:08:11 +0000 (14:08 +0000)
It was not escaped.

src/lib-mail/message-header-encode.c
src/lib-mail/test-message-header-decode.c

index 35454aa67b703b45ab2bd517fa691c19fa5565c2..1958d2abd028fb6236a5d65857f39770ba6800bd 100644 (file)
@@ -94,7 +94,7 @@ void message_header_encode_q(const unsigned char *input, unsigned int len,
                        str_printfa(output, "=%02X", input[i]);
                        break;
                default:
-                       if (input[i] < 32 || (input[i] & 0x80) != 0) {
+                       if (input[i] < 0x20 || input[i] > 0x7e) {
                                line_len_left -= 2;
                                str_printfa(output, "=%02X", input[i]);
                        } else {
index 273c5a23b57a2bb65344e50f43a5346033ccc523..8ac9f9fdde9b4a83e9854eab821bdaffa640cef6 100644 (file)
@@ -60,6 +60,33 @@ static void test_message_header_decode_read_overflow(void)
        test_end();
 }
 
+static void check_encoded(string_t *encoded, unsigned int test_idx)
+{
+       const unsigned char *enc = str_data(encoded), *p, *pend;
+       size_t enc_len = str_len(encoded), cur_line_len = 0;
+
+       p = enc;
+       pend = enc + enc_len;
+       while (p < pend) {
+               if (*p == '\r') {
+                       p++;
+                       continue;
+               }
+               if (*p == '\n') {
+                       test_assert_idx(cur_line_len <= 76, test_idx);
+                       cur_line_len = 0;
+                       p++;
+                       continue;
+               }
+               cur_line_len++;
+               test_assert_idx((*p >= 0x20 && *p <= 0x7e) || *p == '\t',
+                               test_idx);
+               p++;
+       }
+
+       test_assert_idx(cur_line_len <= 76, test_idx);
+}
+
 static void test_message_header_decode_encode_random(void)
 {
        string_t *encoded, *decoded;
@@ -82,6 +109,7 @@ static void test_message_header_decode_encode_random(void)
 
                /* test Q */
                message_header_encode_q(buf, buflen, encoded, 0);
+               check_encoded(encoded, i);
                message_header_decode_utf8(encoded->data, encoded->used,
                                           decoded, NULL);
                test_assert_idx(decoded->used == buflen &&
@@ -92,6 +120,7 @@ static void test_message_header_decode_encode_random(void)
                str_truncate(decoded, 0);
 
                message_header_encode_b(buf, buflen, encoded, 0);
+               check_encoded(encoded, i);
                message_header_decode_utf8(encoded->data, encoded->used,
                                           decoded, NULL);
                test_assert_idx(decoded->used == buflen &&