From: Timo Sirainen Date: Sat, 21 Apr 2018 11:53:25 +0000 (+0300) Subject: lib-mail: message_snippet_generate() - Ignore NULs without shrinking snippet size X-Git-Tag: 2.3.4~270 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3a4767cc50e1e299080f68a05a4842579a2ddd63;p=thirdparty%2Fdovecot%2Fcore.git lib-mail: message_snippet_generate() - Ignore NULs without shrinking snippet size Previously the NULs also weren't in the snippet content, but they were included in the snippet size. --- diff --git a/src/lib-mail/message-snippet.c b/src/lib-mail/message-snippet.c index b42800a252..012d82ced5 100644 --- a/src/lib-mail/message-snippet.c +++ b/src/lib-mail/message-snippet.c @@ -60,6 +60,10 @@ static bool snippet_generate(struct snippet_context *ctx, count += 2; /* because we skip +1 next */ break; } + if (data[i] == '\0') { + /* skip NULs without increasing snippet size */ + break; + } if (data[i] == '\r' || data[i] == '\n' || data[i] == '\t' || data[i] == ' ') { /* skip any leading whitespace */ diff --git a/src/lib-mail/test-message-snippet.c b/src/lib-mail/test-message-snippet.c index 557d429b9f..1401b8fc41 100644 --- a/src/lib-mail/test-message-snippet.c +++ b/src/lib-mail/test-message-snippet.c @@ -84,10 +84,26 @@ static void test_message_snippet(void) test_end(); } +static void test_message_snippet_nuls(void) +{ + const char input_text[] = "\nfoo\0bar"; + string_t *str = t_str_new(128); + struct istream *input; + + test_begin("message snippet with NULs"); + + input = i_stream_create_from_data(input_text, sizeof(input_text)-1); + test_assert(message_snippet_generate(input, 5, str) == 0); + test_assert(strcmp(str_c(str), "fooba") == 0); + i_stream_destroy(&input); + test_end(); +} + int main(void) { static void (*const test_functions[])(void) = { test_message_snippet, + test_message_snippet_nuls, NULL }; return test_run(test_functions);