Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
httpc: accept only LF (instead CR/LF) for HTTP headers to be tolerant…
… according RFC
  • Loading branch information
perexg committed Nov 25, 2014
1 parent 448b0a4 commit fbe1f1f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/httpc.c
Expand Up @@ -850,10 +850,9 @@ int
http_client_run( http_client_t *hc )
{
char *buf, *saveptr, *argv[3], *d, *p;
int ver;
int ver, res, delimsize = 4;
ssize_t r;
size_t len;
int res;

if (hc == NULL)
return 0;
Expand Down Expand Up @@ -882,9 +881,14 @@ http_client_run( http_client_t *hc )

buf = alloca(hc->hc_io_size);

if (!hc->hc_in_data && hc->hc_rpos > 3 &&
(d = strstr(hc->hc_rbuf, "\r\n\r\n")) != NULL)
goto header;
if (!hc->hc_in_data && hc->hc_rpos > 3) {
if ((d = strstr(hc->hc_rbuf, "\r\n\r\n")) != NULL)
goto header;
if ((d = strstr(hc->hc_rbuf, "\n\n")) != NULL) {
delimsize = 2;
goto header;
}
}

retry:
if (hc->hc_ssl)
Expand Down Expand Up @@ -934,16 +938,19 @@ http_client_run( http_client_t *hc )
next_header:
if (hc->hc_rpos < 3)
return HTTP_CON_RECEIVING;
if ((d = strstr(hc->hc_rbuf, "\r\n\r\n")) == NULL)
return HTTP_CON_RECEIVING;
if ((d = strstr(hc->hc_rbuf, "\r\n\r\n")) == NULL) {
delimsize = 2;
if ((d = strstr(hc->hc_rbuf, "\n\n")) == NULL)
return HTTP_CON_RECEIVING;
}

header:
*d = '\0';
len = hc->hc_rpos;
hc->hc_reconnected = 0;
http_client_clear_state(hc);
hc->hc_rpos = len;
hc->hc_hsize = d - hc->hc_rbuf + 4;
hc->hc_hsize = d - hc->hc_rbuf + delimsize;
p = strtok_r(hc->hc_rbuf, "\r\n", &saveptr);
if (p == NULL)
return http_client_flush(hc, -EINVAL);
Expand Down

0 comments on commit fbe1f1f

Please sign in to comment.