commit b17365c5b475fabf5aeed10c7d8f4952337680bf
parent b6aaa50d419125384134d8a4435bac045480eb40
Author: Iván Ávalos <avalos@disroot.org>
Date: Wed, 12 Jun 2024 11:38:56 -0600
use num_response_headers, don't expect headers to be NULL terminated
Diffstat:
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/quickjs/quickjs-http.c b/quickjs/quickjs-http.c
@@ -140,6 +140,7 @@ handle_done(CURL *curl, CURLcode res)
hri.body = crs->response_data.buf;
hri.body_len = crs->response_data.size;
hri.response_headers = headers;
+ hri.num_response_headers = num_headers;
} else {
hri.status = 0;
hri.errmsg = crs->errbuf;
diff --git a/quickjs/quickjs-libc.c b/quickjs/quickjs-libc.c
@@ -2225,14 +2225,9 @@ static void handle_http_resp(void *cls, struct JSHttpResponseInfo *resp_info)
msg->request_id = resp_info->request_id;
if (resp_info->response_headers) {
- int num_headers = 0;
- char **h;
+ int num_headers;
- h = resp_info->response_headers;
- while (*h) {
- num_headers++;
- h++;
- }
+ num_headers = resp_info->num_response_headers;
msg->response_headers = malloc((num_headers + 1) * sizeof (char *));
if (!msg->response_headers) {