tinywebd
diff src/main.c @ 4:9e054c002489
fixed the header parsing bugs
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 16 Apr 2015 17:34:15 +0300 |
parents | 852a745503cf |
children | def49a046566 |
line diff
1.1 --- a/src/main.c Thu Apr 16 15:20:16 2015 +0300 1.2 +++ b/src/main.c Thu Apr 16 17:34:15 2015 +0300 1.3 @@ -99,6 +99,7 @@ 1.4 c = c->next; 1.5 } 1.6 } 1.7 + clist = dummy.next; 1.8 } 1.9 1.10 return 0; /* unreachable */ 1.11 @@ -168,26 +169,24 @@ 1.12 int rdsz, status; 1.13 1.14 while((rdsz = recv(c->s, buf, sizeof buf, 0)) > 0) { 1.15 - if(c->rcvbuf) { 1.16 - char *newbuf; 1.17 - int newsz = c->bufsz + rdsz; 1.18 - if(newsz > MAX_REQ_LENGTH) { 1.19 - respond_error(c, 413); 1.20 - return -1; 1.21 - } 1.22 + char *newbuf; 1.23 + int newsz = c->bufsz + rdsz; 1.24 + if(newsz > MAX_REQ_LENGTH) { 1.25 + respond_error(c, 413); 1.26 + return -1; 1.27 + } 1.28 1.29 - if(!(newbuf = realloc(buf, newsz + 1))) { 1.30 - fprintf(stderr, "failed to allocate %d byte buffer\n", newsz); 1.31 - respond_error(c, 503); 1.32 - return -1; 1.33 - } 1.34 + if(!(newbuf = realloc(c->rcvbuf, newsz + 1))) { 1.35 + fprintf(stderr, "failed to allocate %d byte buffer\n", newsz); 1.36 + respond_error(c, 503); 1.37 + return -1; 1.38 + } 1.39 1.40 - memcpy(newbuf + c->bufsz, buf, rdsz); 1.41 - newbuf[newsz] = 0; 1.42 + memcpy(newbuf + c->bufsz, buf, rdsz); 1.43 + newbuf[newsz] = 0; 1.44 1.45 - c->rcvbuf = newbuf; 1.46 - c->bufsz = newsz; 1.47 - } 1.48 + c->rcvbuf = newbuf; 1.49 + c->bufsz = newsz; 1.50 } 1.51 1.52 if((status = http_parse_header(&hdr, c->rcvbuf, c->bufsz)) != HTTP_HDR_OK) {