Skip to content

Commit 6b966b2

Browse files
committed
Experimental fix for fragmented request lines (needs unit test)
1 parent 9cca5d6 commit 6b966b2

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/HttpParser.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,20 @@ struct HttpParser {
311311
if (memcmp(" HTTP/1.1\r\n", data, 11) == 0) {
312312
return data + 11;
313313
}
314-
return nullptr;
314+
/* If we stand at the post padded CR, we have fragmented input so try again later */
315+
if (data[0] == '\r') {
316+
return nullptr;
317+
}
318+
/* This is an error */
319+
return (char *) 0x1;
315320
}
316321
}
317322
}
318-
return nullptr;
323+
/* If we stand at the post padded CR, we have fragmented input so try again later */
324+
if (data[0] == '\r') {
325+
return nullptr;
326+
}
327+
return (char *) 0x1;
319328
}
320329

321330
/* RFC 9110: 5.5 Field Values (TLDR; anything above 31 is allowed; htab (9) is also allowed)
@@ -364,10 +373,10 @@ struct HttpParser {
364373
* which is then removed, and our counters to flip due to overflow and we end up with a crash */
365374

366375
/* The request line is different from the field names / field values */
367-
if (!(postPaddedBuffer = consumeRequestLine(postPaddedBuffer, headers[0]))) {
376+
if ((char *) 2 > (postPaddedBuffer = consumeRequestLine(postPaddedBuffer, headers[0]))) {
368377
/* Error - invalid request line */
369378
/* Assuming it is 505 HTTP Version Not Supported */
370-
err = HTTP_ERROR_505_HTTP_VERSION_NOT_SUPPORTED;
379+
err = postPaddedBuffer ? HTTP_ERROR_505_HTTP_VERSION_NOT_SUPPORTED : 0;
371380
return 0;
372381
}
373382
headers++;

0 commit comments

Comments
 (0)