From 449d4e581c6b47621d6a3cfd925fa587c640bee4 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 27 Jul 2026 12:03:39 +0200 Subject: [PATCH] CLEANUP: http-conv: index the captures array with hdr->index in the converters smp_conv_req_capture() and smp_conv_res_capture() look the capture slot up by walking the proxy's capture list backwards until the decreasing counter matches the requested id, then allocate the storage using index> but write it using : if (smp->strm->req_cap[hdr->index] == NULL) smp->strm->req_cap[hdr->index] = pool_alloc(hdr->pool); ... memcpy(smp->strm->req_cap[idx], smp->data.u.str.area, len); Both are in fact always equal, because every place that appends to the list (cfgparse-listen.c, proxy.c, tcp_rules.c and http_act.c) does "hdr->next = px-> req_cap; hdr->index = px->nb_req_cap++; px->req_cap = hdr;", so the head always carries the highest index and the walk keeps hdr->index == i. But relying on that invariant to index an array while the neighbouring lines use the field that actually describes the slot is confusing, and it silently ties these two functions to the way the list happens to be built. Let's use hdr->index everywhere. No functional change. --- src/http_conv.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/http_conv.c b/src/http_conv.c index ed276b2e8..65b75239e 100644 --- a/src/http_conv.c +++ b/src/http_conv.c @@ -402,9 +402,12 @@ static int smp_conv_req_capture(const struct arg *args, struct sample *smp, void if (len > hdr->len) len = hdr->len; - /* Capture input data. */ - memcpy(smp->strm->req_cap[idx], smp->data.u.str.area, len); - smp->strm->req_cap[idx][len] = '\0'; + /* Capture input data. Use hdr->index and not idx: while both are equal + * for a properly built capture list, only the former is guaranteed to + * be a valid slot number for the array allocated above. + */ + memcpy(smp->strm->req_cap[hdr->index], smp->data.u.str.area, len); + smp->strm->req_cap[hdr->index][len] = '\0'; return 1; } @@ -447,9 +450,12 @@ static int smp_conv_res_capture(const struct arg *args, struct sample *smp, void if (len > hdr->len) len = hdr->len; - /* Capture input data. */ - memcpy(smp->strm->res_cap[idx], smp->data.u.str.area, len); - smp->strm->res_cap[idx][len] = '\0'; + /* Capture input data. Use hdr->index and not idx: while both are equal + * for a properly built capture list, only the former is guaranteed to + * be a valid slot number for the array allocated above. + */ + memcpy(smp->strm->res_cap[hdr->index], smp->data.u.str.area, len); + smp->strm->res_cap[hdr->index][len] = '\0'; return 1; } -- 2.47.3