From 0d6f7790fbe431b148b2514fb8caf800b428bd77 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Fri, 20 Aug 2021 11:59:49 +0200 Subject: [PATCH] BUG/MINOR: httpclient: check if hdr_num is not 0 Check if hdr_num is not 0 before allocating or copying the headers to the hc->hdrs space. --- src/http_client.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/http_client.c b/src/http_client.c index 89d7d76672..257c2c029e 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -533,15 +533,17 @@ static void httpclient_applet_io_handler(struct appctx *appctx) hdr_num++; } - /* alloc and copy the headers in the httpclient struct */ - hc->res.hdrs = calloc((hdr_num + 1), sizeof(*hc->res.hdrs)); - if (!hc->res.hdrs) - goto end; - memcpy(hc->res.hdrs, hdrs, sizeof(struct http_hdr) * (hdr_num + 1)); - - /* caller callback */ - if (hc->ops.res_headers) - hc->ops.res_headers(hc); + if (hdr_num) { + /* alloc and copy the headers in the httpclient struct */ + hc->res.hdrs = calloc((hdr_num + 1), sizeof(*hc->res.hdrs)); + if (!hc->res.hdrs) + goto end; + memcpy(hc->res.hdrs, hdrs, sizeof(struct http_hdr) * (hdr_num + 1)); + + /* caller callback */ + if (hc->ops.res_headers) + hc->ops.res_headers(hc); + } /* if there is no HTX data anymore and the EOM flag is * set, leave (no body) */ -- 2.47.3