# HG changeset patch # User John Tsiombikas # Date 1429194855 -10800 # Node ID 9e054c0024894f062ff9e25f00bac7b60faa434d # Parent 852a745503cfee8e5e0177257108198bda20135a fixed the header parsing bugs diff -r 852a745503cf -r 9e054c002489 src/http.c --- a/src/http.c Thu Apr 16 15:20:16 2015 +0300 +++ b/src/http.c Thu Apr 16 17:34:15 2015 +0300 @@ -146,11 +146,12 @@ startln = buf; endln = buf; - for(i=1; ibody_offset; i++) { + for(i=1; ibody_offset - 2; i++) { if(buf[i] == '\n' && buf[i - 1] == '\r') { int linesz; + endln = buf + i - 1; - linesz = endln - startln - 1; + linesz = endln - startln; if(startln > buf) { /* skip first line */ int idx = hdr->num_hdrfields++; diff -r 852a745503cf -r 9e054c002489 src/main.c --- a/src/main.c Thu Apr 16 15:20:16 2015 +0300 +++ b/src/main.c Thu Apr 16 17:34:15 2015 +0300 @@ -99,6 +99,7 @@ c = c->next; } } + clist = dummy.next; } return 0; /* unreachable */ @@ -168,26 +169,24 @@ int rdsz, status; while((rdsz = recv(c->s, buf, sizeof buf, 0)) > 0) { - if(c->rcvbuf) { - char *newbuf; - int newsz = c->bufsz + rdsz; - if(newsz > MAX_REQ_LENGTH) { - respond_error(c, 413); - return -1; - } + char *newbuf; + int newsz = c->bufsz + rdsz; + if(newsz > MAX_REQ_LENGTH) { + respond_error(c, 413); + return -1; + } - if(!(newbuf = realloc(buf, newsz + 1))) { - fprintf(stderr, "failed to allocate %d byte buffer\n", newsz); - respond_error(c, 503); - return -1; - } + if(!(newbuf = realloc(c->rcvbuf, newsz + 1))) { + fprintf(stderr, "failed to allocate %d byte buffer\n", newsz); + respond_error(c, 503); + return -1; + } - memcpy(newbuf + c->bufsz, buf, rdsz); - newbuf[newsz] = 0; + memcpy(newbuf + c->bufsz, buf, rdsz); + newbuf[newsz] = 0; - c->rcvbuf = newbuf; - c->bufsz = newsz; - } + c->rcvbuf = newbuf; + c->bufsz = newsz; } if((status = http_parse_header(&hdr, c->rcvbuf, c->bufsz)) != HTTP_HDR_OK) {