src/server/util/io.c

changeset 549
b26bec196a2e
parent 548
40ecc0a6b280
equal deleted inserted replaced
548:40ecc0a6b280 549:b26bec196a2e
618 } 618 }
619 } 619 }
620 if(!hdr_end || i == len) { 620 if(!hdr_end || i == len) {
621 return 0; // incomplete 621 return 0; // incomplete
622 } 622 }
623 623
624 if(*hdr_end == '\r') { 624 if(*hdr_end == '\r') {
625 // we also need '\n' 625 // we also need '\n'
626 if(hdr_end[1] != '\n') { 626 if(hdr_end[1] != '\n') {
627 return -1; 627 return -1;
628 } 628 }
629 i++; // '\n' found 629 i++; // '\n' found
630 }
631
632 // check if the first character is a number
633 char f = hdr_start[0];
634 if(!(isdigit(f) || (f >= 'A' && f <= 'F') || (f >= 'a' && f <= 'f'))) {
635 return -1;
630 } 636 }
631 637
632 // parse 638 // parse
633 char save_c = *hdr_end; 639 char save_c = *hdr_end;
634 *hdr_end = '\0'; 640 *hdr_end = '\0';
635 char *end; 641 char *end;
636 int64_t clen; 642 int64_t clen;
637 errno = 0; 643 errno = 0;
638 clen = strtoll(hdr_start, &end, 16); 644 clen = strtoll(hdr_start, &end, 16);
639 *hdr_end = save_c; 645 *hdr_end = save_c;
640 if(end != hdr_end) { 646 if(errno == 0 && end != hdr_end) {
641 return -1; 647 return -1;
642 } 648 }
643 i++; 649 i++;
644 650
645 if(clen == 0) { 651 if(clen == 0) {

mercurial