From 04c20d746056fd051bd748680cbf8886c737c3a3 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 30 Jun 2020 17:50:01 +0100 Subject: [PATCH] ah: workaround for broken routers with no http header delimiter There's a type of router in the wild issuing malformed http when in captive portal mode... there's no \x0a\x0d but just \x0a --- .gitignore | 1 + lib/roles/http/parsers.c | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index fd50d0294..1fb8b7e09 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,4 @@ doc /cros/ /q/ /b1/ +/destdir/ diff --git a/lib/roles/http/parsers.c b/lib/roles/http/parsers.c index d91b40d35..b74669b17 100644 --- a/lib/roles/http/parsers.c +++ b/lib/roles/http/parsers.c @@ -1065,12 +1065,18 @@ lws_parse(struct lws *wsi, unsigned char *buf, int *len) check_eol: /* bail at EOL */ if (ah->parser_state != WSI_TOKEN_CHALLENGE && - c == '\x0d') { + (c == '\x0d' || c == '\x0a')) { if (ah->ues != URIES_IDLE) goto forbid; + if (c == '\x0a') { + /* broken peer */ + ah->parser_state = WSI_TOKEN_NAME_PART; + ah->unk_pos = ah->lextable_pos = 0; + } else + ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR; + c = '\0'; - ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR; lwsl_parser("*\n"); } @@ -1095,6 +1101,10 @@ swallow: (unsigned long)lwsi_role(wsi), ah->lextable_pos); + if (!ah->unk_pos && c == '\x0a') + /* broken peer */ + goto set_parsing_complete; + if (c >= 'A' && c <= 'Z') c += 'a' - 'A'; /* @@ -1391,6 +1401,12 @@ excessive: case WSI_TOKEN_SKIPPING: lwsl_parser("WSI_TOKEN_SKIPPING '%c'\n", c); + if (c == '\x0a') { + /* broken peer */ + ah->parser_state = WSI_TOKEN_NAME_PART; + ah->unk_pos = ah->lextable_pos = 0; + } + if (c == '\x0d') ah->parser_state = WSI_TOKEN_SKIPPING_SAW_CR; break;