Skip to content

Commit 0cfa70b

Browse files
committed
Fix to return an error response when multiple content-lengths headers are present.
1 parent 94fc8dc commit 0cfa70b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

meinheld/server/http_parser.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ do { \
115115
FOR##_mark = NULL; \
116116
} \
117117
} while (0)
118-
118+
119119
/* Run the data callback FOR and consume the current byte */
120120
#define CALLBACK_DATA(FOR) \
121121
CALLBACK_DATA_(FOR, p - FOR##_mark, p - data + 1)
@@ -1389,7 +1389,7 @@ size_t http_parser_execute (http_parser *parser,
13891389
}
13901390

13911391
c = LOWER(ch);
1392-
1392+
13931393
switch (parser->header_state) {
13941394
case h_upgrade:
13951395
parser->flags |= F_UPGRADE;
@@ -1410,8 +1410,13 @@ size_t http_parser_execute (http_parser *parser,
14101410
SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
14111411
goto error;
14121412
}
1413+
if (parser->set_content_length > 0) {
1414+
SET_ERRNO(HPE_INVALID_CONTENT_LENGTH);
1415+
goto error;
1416+
}
14131417

14141418
parser->content_length = ch - '0';
1419+
parser->set_content_length = 1;
14151420
break;
14161421

14171422
case h_connection:
@@ -1449,7 +1454,7 @@ size_t http_parser_execute (http_parser *parser,
14491454
}
14501455

14511456
c = LOWER(ch);
1452-
1457+
14531458
switch (parser->header_state) {
14541459
case h_general:
14551460
break;

meinheld/server/http_parser.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ enum flags
141141

142142

143143
/* Map for errno-related constants
144-
*
144+
*
145145
* The provided argument should be a macro that takes 2 arguments.
146146
*/
147147
#define HTTP_ERRNO_MAP(XX) \
@@ -214,6 +214,7 @@ struct http_parser {
214214

215215
uint32_t nread; /* # bytes read in various scenarios */
216216
uint64_t content_length; /* # bytes in body (0 if no Content-Length header) */
217+
unsigned char set_content_length;
217218

218219
/** READ-ONLY **/
219220
unsigned short http_major;

0 commit comments

Comments
 (0)