Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib-mail/mbox-from.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ int mbox_from_parse(const unsigned char *msg, size_t size,

if (!alt_stamp) {
/* year */
if (mbox_parse_year(msg, &tm) < 0)
if (msg + 4 > msg_end || mbox_parse_year(msg, &tm) < 0)
return -1;
msg += 4;
}
Expand Down
23 changes: 23 additions & 0 deletions src/lib-mail/test-mbox-from.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ static void test_mbox_from_parse(void)
}
}

static void test_mbox_from_parse_no_overread(void)
{
/* A truncated non-alt date whose trailing space leaves the parser
pointing exactly at the end of the input when the year field is
read. Feed it from an exact-size heap buffer so an over-read past
msg+size is caught under valgrind/ASAN. */
const char *date = "x Fri Jan 22 12:34:56 ";
size_t len = strlen(date);
unsigned char *buf = i_malloc(len);
char *sender = NULL;
time_t t;
int tz, ret;

test_begin("mbox_from_parse() no over-read of year");
memcpy(buf, date, len);
ret = mbox_from_parse(buf, len, &t, &tz, &sender);
test_assert(ret < 0);
i_free(sender);
i_free(buf);
test_end();
}

static void test_mbox_from_create(void)
{
time_t t = 1234567890;
Expand All @@ -97,6 +119,7 @@ int main(void)
{
static void (*const test_functions[])(void) = {
test_mbox_from_parse,
test_mbox_from_parse_no_overread,
test_mbox_from_create,
NULL
};
Expand Down