Skip to content

Commit c0dc186

Browse files
authored
Merge pull request #4776 from cyrusimap/message_parse_received_date_once
message.c: only attempt to read first Received header date
2 parents b750123 + b6470e4 commit c0dc186

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Diff for: cunit/message.testc

+20-5
Original file line numberDiff line numberDiff line change
@@ -1392,16 +1392,31 @@ static void test_parse_bogus_charset_params(void)
13921392
}
13931393

13941394
/*
1395-
* Verifies that message_parse_received_date() does not read
1396-
* uninitialized data in the second call to message_parse_string()
1395+
* Verifies that message_parse_received_date() does not
1396+
* read any but the first Received header for invalid values.
13971397
*/
13981398
static void test_parse_received_semicolon(void)
13991399
{
1400-
static const char msg[] = "Received: abc;\r\n\r\nd";
1400+
static const char msg_emptydate[] =
1401+
"Received: abc;\r\n"
1402+
"Received: from foo by bar; Fri, 29 Oct 2010 13:05:01 +1100\r\n"
1403+
"\r\n";
14011404
struct body body;
14021405
memset(&body, 0x45, sizeof(body));
1403-
CU_ASSERT_EQUAL(message_parse_mapped(msg, sizeof(msg)-1, &body, NULL), 0);
1404-
CU_ASSERT_PTR_NULL(body.received_date);
1406+
CU_ASSERT_EQUAL(message_parse_mapped(msg_emptydate,
1407+
sizeof(msg_emptydate)-1, &body, NULL), 0);
1408+
CU_ASSERT_STRING_EQUAL(body.received_date, "");
14051409
message_free_body(&body);
1410+
1411+
static const char msg_nodate[] =
1412+
"Received: abc\r\n"
1413+
"Received: from foo by bar; Fri, 29 Oct 2010 13:05:01 +1100\r\n"
1414+
"\r\n";
1415+
memset(&body, 0x45, sizeof(body));
1416+
CU_ASSERT_EQUAL(message_parse_mapped(msg_nodate,
1417+
sizeof(msg_nodate)-1, &body, NULL), 0);
1418+
CU_ASSERT_STRING_EQUAL(body.received_date, "abc");
1419+
message_free_body(&body);
1420+
14061421
}
14071422
/* vim: set ft=c: */

Diff for: imap/message.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ static void message_parse_received_date(const char *hdr, char **hdrp)
20182018
/* No date string after ; - treat as non-existent */
20192019
if (curp[1] == '\0') {
20202020
free(hdrbuf);
2021-
*hdrp = NULL;
2021+
*hdrp = xzmalloc(1);
20222022
return;
20232023
}
20242024

0 commit comments

Comments
 (0)