From: Timo Sirainen Date: Fri, 23 Dec 2016 18:30:56 +0000 (-0500) Subject: lib-mail: istream-qp-decoder: set stream_errno=EPIPE on unexpected EOF X-Git-Tag: 2.3.0.rc1~2362 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a4883ee9daf4e3a463faf43b304fd44b21aa73ee;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: istream-qp-decoder: set stream_errno=EPIPE on unexpected EOF --- diff --git a/src/lib-mail/istream-qp-decoder.c b/src/lib-mail/istream-qp-decoder.c index c77a91fef8..2b3b7e7fcf 100644 --- a/src/lib-mail/istream-qp-decoder.c +++ b/src/lib-mail/istream-qp-decoder.c @@ -83,7 +83,7 @@ static ssize_t i_stream_qp_decoder_read(struct istream_private *stream) } io_stream_set_error(&stream->iostream, "Invalid quoted-printable input trailer: %s", error); - stream->istream.stream_errno = EINVAL; + stream->istream.stream_errno = EPIPE; return -1; } if (qp_decoder_more(bstream->qp, data, size, diff --git a/src/lib-mail/test-istream-qp-decoder.c b/src/lib-mail/test-istream-qp-decoder.c index 93a334d65a..0a3fe681ec 100644 --- a/src/lib-mail/test-istream-qp-decoder.c +++ b/src/lib-mail/test-istream-qp-decoder.c @@ -8,21 +8,21 @@ static const struct { const char *input; const char *output; - int ret; + int stream_errno; } tests[] = { { "p=C3=A4=C3=A4t=C3=B6s", "p\xC3\xA4\xC3\xA4t\xC3\xB6s", 0 }, { "p=c3=a4=c3=a4t=c3=b6s= \n", "p\xC3\xA4\xC3\xA4t\xC3\xB6s", 0 }, { "p=c3=a4= \t \n=c3=\r\n=a4t= \r\n=c3=b6s", "p\xC3\xA4\xC3\xA4t\xC3\xB6s", 0 }, - { "p=c3=a4\rasdf", "p\xC3\xA4", -1 }, - { "p=c", "p", -1 }, - { "p=A", "p", -1 }, - { "p=Ax", "p", -1 }, - { "p=c3=a4=c3=a4t=c3=b6s= ", "p\xC3\xA4\xC3\xA4t\xC3\xB6s", -1 } + { "p=c3=a4\rasdf", "p\xC3\xA4", EINVAL }, + { "p=c", "p", EPIPE }, + { "p=A", "p", EPIPE }, + { "p=Ax", "p", EINVAL }, + { "p=c3=a4=c3=a4t=c3=b6s= ", "p\xC3\xA4\xC3\xA4t\xC3\xB6s", EPIPE } }; static void -decode_test(const char *qp_input, const char *output, bool broken_input, +decode_test(const char *qp_input, const char *output, int stream_errno, unsigned int buffer_size) { size_t qp_input_len = strlen(qp_input); @@ -43,7 +43,7 @@ decode_test(const char *qp_input, const char *output, bool broken_input, str_append_n(str, data, size); i_stream_skip(input, size); } - if (ret == -1 && broken_input) + if (ret == -1 && stream_errno != 0) break; test_assert(ret == 0); } @@ -55,8 +55,7 @@ decode_test(const char *qp_input, const char *output, bool broken_input, } } test_assert(ret == -1); - test_assert((input->stream_errno == 0 && !broken_input) || - (input->stream_errno == EINVAL && broken_input)); + test_assert(input->stream_errno == stream_errno); test_assert(strcmp(str_c(str), output) == 0); i_stream_unref(&input); @@ -71,7 +70,7 @@ static void test_istream_qp_decoder(void) test_begin(t_strdup_printf("istream qp decoder %u", i+1)); for (j = 1; j < 10; j++) T_BEGIN { decode_test(tests[i].input, tests[i].output, - tests[i].ret == -1, j); + tests[i].stream_errno, j); } T_END; test_end(); }