Skip to content

Commit 157bc9a

Browse files
committed
Revert "Fail requests with incomplete line ends (#8096)"
This reverts commit 2c8bb98.
1 parent 2e2bcd4 commit 157bc9a

56 files changed

Lines changed: 195 additions & 200 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ci/rat-regex.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
.*\.config$
2525
.*\.yaml$
2626
.*\.gold$
27-
.*\.test_input$
2827
^\.gitignore$
2928
^\.gitmodules$
3029
^\.perltidyrc$

proxy/hdrs/MIME.cc

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,8 @@ ParseResult
23492349
MIMEScanner::get(TextView &input, TextView &output, bool &output_shares_input, bool eof_p, ScanType scan_type)
23502350
{
23512351
ParseResult zret = PARSE_RESULT_CONT;
2352+
// Need this for handling dangling CR.
2353+
static const char RAW_CR{ParseRules::CHAR_CR};
23522354

23532355
auto text = input;
23542356
while (PARSE_RESULT_CONT == zret && !text.empty()) {
@@ -2366,7 +2368,7 @@ MIMEScanner::get(TextView &input, TextView &output, bool &output_shares_input, b
23662368
}
23672369
} else if (ParseRules::is_lf(*text)) {
23682370
++text;
2369-
zret = PARSE_RESULT_ERROR; // lone LF
2371+
zret = PARSE_RESULT_DONE; // Required by regression test.
23702372
} else {
23712373
// consume this character in the next state.
23722374
m_state = MIME_PARSE_INSIDE;
@@ -2378,28 +2380,21 @@ MIMEScanner::get(TextView &input, TextView &output, bool &output_shares_input, b
23782380
++text;
23792381
zret = PARSE_RESULT_DONE;
23802382
} else {
2381-
zret = PARSE_RESULT_ERROR; // lone CR
2383+
// This really should be an error (spec doesn't permit lone CR) but the regression tests
2384+
// require it.
2385+
this->append(TextView(&RAW_CR, 1)); // This is to fix a core dump of the icc 19.1 compiler when {&RAW_CR, 1} is used
2386+
m_state = MIME_PARSE_INSIDE;
23822387
}
23832388
break;
23842389
case MIME_PARSE_INSIDE: {
2385-
auto cr_off = text.find(ParseRules::CHAR_CR);
2386-
if (cr_off != TextView::npos) {
2387-
text.remove_prefix(cr_off + 1); // drop up to and including CR
2388-
// Is the next item a LF?
2389-
if (!text.empty()) {
2390-
if (text[0] == ParseRules::CHAR_LF) {
2391-
text.remove_prefix(1); // drop up to and including LF
2392-
if (LINE == scan_type) {
2393-
zret = PARSE_RESULT_OK;
2394-
m_state = MIME_PARSE_BEFORE;
2395-
} else {
2396-
m_state = MIME_PARSE_AFTER; // looking for line folding.
2397-
}
2398-
} else { // Next char is not LF, you lose
2399-
zret = PARSE_RESULT_ERROR;
2400-
}
2401-
} else { // No LF yet, adjust state to note
2402-
m_state = MIME_PARSE_FOUND_CR;
2390+
auto lf_off = text.find(ParseRules::CHAR_LF);
2391+
if (lf_off != TextView::npos) {
2392+
text.remove_prefix(lf_off + 1); // drop up to and including LF
2393+
if (LINE == scan_type) {
2394+
zret = PARSE_RESULT_OK;
2395+
m_state = MIME_PARSE_BEFORE;
2396+
} else {
2397+
m_state = MIME_PARSE_AFTER; // looking for line folding.
24032398
}
24042399
} else { // no EOL, consume all text without changing state.
24052400
text.remove_prefix(text.size());
@@ -2536,14 +2531,18 @@ mime_parser_parse(MIMEParser *parser, HdrHeap *heap, MIMEHdrImpl *mh, const char
25362531
return err;
25372532
}
25382533

2539-
///////////////////////////////////////////////////
2540-
// if got a CR and LF on its own, end the header //
2541-
///////////////////////////////////////////////////
2534+
//////////////////////////////////////////////////
2535+
// if got a LF or CR on its own, end the header //
2536+
//////////////////////////////////////////////////
25422537

25432538
if ((parsed.size() >= 2) && (parsed[0] == ParseRules::CHAR_CR) && (parsed[1] == ParseRules::CHAR_LF)) {
25442539
return PARSE_RESULT_DONE;
25452540
}
25462541

2542+
if ((parsed.size() >= 1) && (parsed[0] == ParseRules::CHAR_LF)) {
2543+
return PARSE_RESULT_DONE;
2544+
}
2545+
25472546
/////////////////////////////////////////////
25482547
// find pointers into the name:value field //
25492548
/////////////////////////////////////////////

proxy/hdrs/unit_tests/test_Hdrs.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,24 @@ TEST_CASE("HdrTestHttpParse", "[proxy][hdrtest]")
4545
int expected_result;
4646
int expected_bytes_consumed;
4747
};
48-
static const std::array<Test, 23> tests = {{
48+
static const std::array<Test, 21> tests = {{
4949
{"GET /index.html HTTP/1.0\r\n", PARSE_RESULT_DONE, 26},
5050
{"GET /index.html HTTP/1.0\r\n\r\n***BODY****", PARSE_RESULT_DONE, 28},
51-
{"GET /index.html HTTP/1.0\r\na\rb\n", PARSE_RESULT_ERROR, 28},
52-
{"GET /index.html HTTP/1.0\r\nUser-Agent: foobar\r \n", PARSE_RESULT_ERROR, 45},
5351
{"GET /index.html HTTP/1.0\r\nUser-Agent: foobar\r\n\r\n***BODY****", PARSE_RESULT_DONE, 48},
5452
{"GET", PARSE_RESULT_ERROR, 3},
5553
{"GET /index.html", PARSE_RESULT_ERROR, 15},
5654
{"GET /index.html\r\n", PARSE_RESULT_ERROR, 17},
5755
{"GET /index.html HTTP/1.0", PARSE_RESULT_ERROR, 24},
5856
{"GET /index.html HTTP/1.0\r", PARSE_RESULT_ERROR, 25},
59-
{"GET /index.html HTTP/1.0\n", PARSE_RESULT_ERROR, 25},
60-
{"GET /index.html HTTP/1.0\n\n", PARSE_RESULT_ERROR, 26},
57+
{"GET /index.html HTTP/1.0\n", PARSE_RESULT_DONE, 25},
58+
{"GET /index.html HTTP/1.0\n\n", PARSE_RESULT_DONE, 26},
6159
{"GET /index.html HTTP/1.0\r\n\r\n", PARSE_RESULT_DONE, 28},
6260
{"GET /index.html HTTP/1.0\r\nUser-Agent: foobar", PARSE_RESULT_ERROR, 44},
63-
{"GET /index.html HTTP/1.0\r\nUser-Agent: foobar\n", PARSE_RESULT_ERROR, 45},
61+
{"GET /index.html HTTP/1.0\r\nUser-Agent: foobar\n", PARSE_RESULT_DONE, 45},
6462
{"GET /index.html HTTP/1.0\r\nUser-Agent: foobar\r\n", PARSE_RESULT_DONE, 46},
6563
{"GET /index.html HTTP/1.0\r\nUser-Agent: foobar\r\n\r\n", PARSE_RESULT_DONE, 48},
66-
{"GET /index.html HTTP/1.0\nUser-Agent: foobar\n", PARSE_RESULT_ERROR, 44},
67-
{"GET /index.html HTTP/1.0\nUser-Agent: foobar\nBoo: foo\n", PARSE_RESULT_ERROR, 53},
64+
{"GET /index.html HTTP/1.0\nUser-Agent: foobar\n", PARSE_RESULT_DONE, 44},
65+
{"GET /index.html HTTP/1.0\nUser-Agent: foobar\nBoo: foo\n", PARSE_RESULT_DONE, 53},
6866
{"GET /index.html HTTP/1.0\r\nUser-Agent: foobar\r\n", PARSE_RESULT_DONE, 46},
6967
{"GET /index.html HTTP/1.0\r\n", PARSE_RESULT_DONE, 26},
7068
{"GET /index.html hTTP/1.0\r\n", PARSE_RESULT_ERROR, 26},

tests/gold_tests/body_factory/data/www.customplugin204.test_get.test_input renamed to tests/gold_tests/body_factory/data/www.customplugin204.test_get.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
GET HTTP://www.customplugin204.test/ HTTP/1.1
2-
1+
GET HTTP://www.customplugin204.test/ HTTP/1.1
2+

tests/gold_tests/body_factory/data/www.customtemplate204.test_get.test_input renamed to tests/gold_tests/body_factory/data/www.customtemplate204.test_get.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
GET HTTP://www.customtemplate204.test/ HTTP/1.1
2-
1+
GET HTTP://www.customtemplate204.test/ HTTP/1.1
2+

tests/gold_tests/body_factory/data/www.default204.test_get.test_input renamed to tests/gold_tests/body_factory/data/www.default204.test_get.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
GET HTTP://www.default204.test/ HTTP/1.1
2-
1+
GET HTTP://www.default204.test/ HTTP/1.1
2+

tests/gold_tests/body_factory/data/www.default304.test_get.test_input renamed to tests/gold_tests/body_factory/data/www.default304.test_get.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
GET HTTP://www.default304.test/ HTTP/1.1
2-
1+
GET HTTP://www.default304.test/ HTTP/1.1
2+

tests/gold_tests/body_factory/data/www.example.test_get_200.test_input renamed to tests/gold_tests/body_factory/data/www.example.test_get_200.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
GET /get200 HTTP/1.1
2-
Host: www.example.test
3-
1+
GET /get200 HTTP/1.1
2+
Host: www.example.test
3+

tests/gold_tests/body_factory/data/www.example.test_get_304.test_input renamed to tests/gold_tests/body_factory/data/www.example.test_get_304.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
GET /get304 HTTP/1.1
2-
Host: www.example.test
3-
If-Modified-Since: Thu, 1 Jan 1970 00:00:00 GMT
4-
1+
GET /get304 HTTP/1.1
2+
Host: www.example.test
3+
If-Modified-Since: Thu, 1 Jan 1970 00:00:00 GMT
4+

tests/gold_tests/body_factory/data/www.example.test_head.test_input renamed to tests/gold_tests/body_factory/data/www.example.test_head.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
HEAD http://www.example.test/ HTTP/1.1
2-
Host: www.example.test
3-
1+
HEAD http://www.example.test/ HTTP/1.1
2+
Host: www.example.test
3+

0 commit comments

Comments
 (0)