Skip to content

Commit

Permalink
Merge pull request #21 from lil-skelly/fix-http-parse-content-length
Browse files Browse the repository at this point in the history
Added proper error handling in the parse_http_content_length function
  • Loading branch information
lil-skelly authored Sep 10, 2024
2 parents 8db546f + 8f9b6ef commit dfcd350
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/client/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ long parse_http_content_length(const char *buf) {
const char *content_length_start;
char *endptr;
long content_length;
char *tmp;

content_length_start =
strstr(buf, CONTENT_LENGTH_HEADER) + strlen(CONTENT_LENGTH_HEADER);
tmp = strstr(buf, CONTENT_LENGTH_HEADER);
if (tmp == NULL) {
perror("No content length found\n");
return -HTTP_INVALID_RESPONSE;
}
content_length_start = tmp + strlen(CONTENT_LENGTH_HEADER);

content_length = strtol(content_length_start, &endptr, 10);
if (endptr == content_length_start) {
Expand Down

0 comments on commit dfcd350

Please sign in to comment.