Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

Allow duplicated Content-Length with the same value #460

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
21 changes: 15 additions & 6 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,12 +1424,6 @@ size_t http_parser_execute (http_parser *parser,
goto error;
}

if (parser->flags & F_CONTENTLENGTH) {
SET_ERRNO(HPE_UNEXPECTED_CONTENT_LENGTH);
goto error;
}

parser->flags |= F_CONTENTLENGTH;
parser->content_length = ch - '0';
parser->header_state = h_content_length_num;
break;
Expand Down Expand Up @@ -1695,6 +1689,21 @@ size_t http_parser_execute (http_parser *parser,
case h_connection_upgrade:
parser->flags |= F_CONNECTION_UPGRADE;
break;
case h_content_length_num:
case h_content_length_ws:
if (parser->flags & F_CONTENTLENGTH) {
/* content length sent multiple times,
* check if value is the same */
if (parser->initial_content_length != parser->content_length) {
SET_ERRNO(HPE_UNEXPECTED_CONTENT_LENGTH);
goto error;
}
} else {
/* set content length flag */
parser->flags |= F_CONTENTLENGTH;
parser->initial_content_length = parser->content_length;
}
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions http_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ struct http_parser {

uint32_t nread; /* # bytes read in various scenarios */
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
uint64_t initial_content_length; /* # used to verify same value if Content-Length header occurs multiple times */

/** READ-ONLY **/
unsigned short http_major;
Expand Down