http-parser.c

Small C library to parse HTTP requests
Log | Files | Refs | README | LICENSE

commit 7332544e0d06855ec7dd98b5a42cf57928215f84
parent 952f81b4faa8fc923fab2f5fc7da82b9b28deca1
Author: finwo <finwo@pm.me>
Date:   Thu,  1 Jun 2023 23:47:10 +0200

Fix heap corruption issue during sprint_response

Diffstat:
Msrc/http-parser.c | 10+++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/http-parser.c b/src/http-parser.c @@ -315,13 +315,13 @@ char * http_parser_sprint_response(struct http_parser_message *response) { index = strlen(result); length = index + strlen(header->key) + - 2 + + 2 + // ": " strlen(header->value) + - 3 + - 3; + 3; // \r\n\0 // Asign memory result = realloc(result,length); + if (!result) exit(1); // Likely out of memory *(result + length) = '\0'; // Write header @@ -376,9 +376,9 @@ char * http_parser_sprint_request(struct http_parser_message *request) { index = strlen(result); length = index + strlen(header->key) + - 2 + + 2 + // ": " strlen(header->value) + - 3; + 3; // \r\n\0 // Asign memory result = realloc(result,length);