Skip to content

Commit

Permalink
lib-mail: message_snippet_generate() - Ignore NULs without shrinking …
Browse files Browse the repository at this point in the history
…snippet size

Previously the NULs also weren't in the snippet content, but they were
included in the snippet size.
  • Loading branch information
sirainen committed Apr 21, 2018
1 parent d0dc630 commit 9abd4cb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib-mail/message-snippet.c
Expand Up @@ -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 */
Expand Down
16 changes: 16 additions & 0 deletions src/lib-mail/test-message-snippet.c
Expand Up @@ -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);
Expand Down

0 comments on commit 9abd4cb

Please sign in to comment.