Skip to content

Commit

Permalink
Merge pull request #4774 from cyrusimap/message_parse_received_date_i…
Browse files Browse the repository at this point in the history
…nvalid_read

Message parse received date invalid read
  • Loading branch information
rsto authored Dec 18, 2023
2 parents fe6ac73 + e14ef0a commit 9360217
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cunit/message.testc
Original file line number Diff line number Diff line change
Expand Up @@ -1391,4 +1391,17 @@ static void test_parse_bogus_charset_params(void)
#undef TESTCASE
}

/*
* Verifies that message_parse_received_date() does not read
* uninitialized data in the second call to message_parse_string()
*/
static void test_parse_received_semicolon(void)
{
static const char msg[] = "Received: abc;\r\n\r\nd";
struct body body;
memset(&body, 0x45, sizeof(body));
CU_ASSERT_EQUAL(message_parse_mapped(msg, sizeof(msg)-1, &body, NULL), 0);
CU_ASSERT_PTR_NULL(body.received_date);
message_free_body(&body);
}
/* vim: set ft=c: */
7 changes: 7 additions & 0 deletions imap/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,13 @@ static void message_parse_received_date(const char *hdr, char **hdrp)
return;
}

/* No date string after ; - treat as non-existent */
if (curp[1] == '\0') {
free(hdrbuf);
*hdrp = NULL;
return;
}

/* Found it, copy out date string part */
curp++;
message_parse_string(curp, hdrp);
Expand Down

0 comments on commit 9360217

Please sign in to comment.