Skip to content

Commit 1958b0f

Browse files
dennis-tseng99vathpela
authored andcommitted
reject message with different values in multiple Content-Length header field
If multiple headers occur, usually the last header would have authority; however the section 3.3.3 of RFC 7230 states that: If a message is received without Transfer-Encoding and with either multiple Content-Length header fields having differing field-values or ..., then the message framing is invalid and the recipient MUST treat it as an unrecoverable error. For example: If there are 2 headers, for example, "Content-Length: 42" and "Content-Length: 52", then current shim httpboot.c will accept the last one which is "Content-Length": 52". This is not correct. This patch allows multiple values if they are the same, but rejects message if any different value is found. In function receive_http_response() of httpboot.c, each received duplicate Content-Length field must be checked whether its value is different. If it is, then this message is invalid. Signed-off-by: Dennis Tseng <dennis.tseng@suse.com>
1 parent 489af5e commit 1958b0f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

httpboot.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ receive_http_response(EFI_HTTP_PROTOCOL *http, VOID **buffer, UINT64 *buf_size)
562562
EFI_HTTP_RESPONSE_DATA response;
563563
EFI_HTTP_STATUS_CODE http_status;
564564
BOOLEAN response_done;
565-
UINTN i, downloaded;
565+
UINTN i, j, downloaded;
566566
CHAR8 rx_buffer[9216];
567567
EFI_STATUS efi_status;
568568
EFI_STATUS event_status;
@@ -619,6 +619,15 @@ receive_http_response(EFI_HTTP_PROTOCOL *http, VOID **buffer, UINT64 *buf_size)
619619
if (!strcasecmp(rx_message.Headers[i].FieldName,
620620
(CHAR8 *)"Content-Length")) {
621621
*buf_size = ascii_to_int(rx_message.Headers[i].FieldValue);
622+
for(j = 0; j < i; j++) {
623+
if (!strcasecmp(rx_message.Headers[i].FieldName,
624+
(CHAR8 *)"Content-Length")) {
625+
if (*buf_size != ascii_to_int(rx_message.Headers[j].FieldValue)) {
626+
perror(L"Content-Length is invalid\n");
627+
goto error;
628+
}
629+
}
630+
}
622631
}
623632
}
624633

0 commit comments

Comments
 (0)