]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-mail: message_snippet_generate() - Ignore NULs without shrinking snippet size
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 21 Apr 2018 11:53:25 +0000 (14:53 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 30 Aug 2018 08:12:08 +0000 (11:12 +0300)
Previously the NULs also weren't in the snippet content, but they were
included in the snippet size.

src/lib-mail/message-snippet.c
src/lib-mail/test-message-snippet.c

index b42800a252f68eb2e882d404e69ca044a044729c..012d82ced5cc86df3ddd4c4327987daf16da669e 100644 (file)
@@ -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 */
index 557d429b9fd4e9e702849dcfa84544b69a4fffd3..1401b8fc41980839a8229f79b0b059c503682f41 100644 (file)
@@ -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);