altsvc: fix parser for lines ending with CRLF

Fixed the alt-svc parser to treat a newline as end of line.

The unit tests in test 1654 were done without CRLF and thus didn't quite
match the real world. Now they use CRLF as well.

Reported-by: Peter Wu
Assisted-by: Peter Wu
Assisted-by: Jay Satiro
Fixes #5445
Closes #5446
This commit is contained in:
Daniel Stenberg 2020-05-25 08:31:08 +02:00
parent 308c243db5
commit d844f2b9ff
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 17 additions and 12 deletions

View file

@ -431,6 +431,8 @@ static time_t debugtime(void *unused)
#define time(x) debugtime(x)
#endif
#define ISNEWLINE(x) (((x) == '\n') || (x) == '\r')
/*
* Curl_altsvc_parse() takes an incoming alt-svc response header and stores
* the data correctly in the cache.
@ -520,12 +522,12 @@ CURLcode Curl_altsvc_parse(struct Curl_easy *data,
/* Handle the optional 'ma' and 'persist' flags. Unknown flags
are skipped. */
for(;;) {
while(*p && ISBLANK(*p) && *p != ';' && *p != ',')
while(ISBLANK(*p))
p++;
if(!*p || *p == ',')
if(*p != ';')
break;
p++; /* pass the semicolon */
if(!*p)
if(!*p || ISNEWLINE(*p))
break;
result = getalnum(&p, option, sizeof(option));
if(result) {