From: William Lallemand Date: Fri, 20 Aug 2021 09:59:49 +0000 (+0200) Subject: BUG/MINOR: httpclient: check if hdr_num is not 0 X-Git-Tag: v2.5-dev5~49 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=0d6f7790fbe431b148b2514fb8caf800b428bd77;p=haproxy-2.5.git 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. --- diff --git a/src/http_client.c b/src/http_client.c index 89d7d76..257c2c0 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) */