]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: sample: Adjust sample size capacity after pointer shift for ltrim()
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Jul 2026 15:50:20 +0000 (17:50 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 21 Jul 2026 05:29:50 +0000 (07:29 +0200)
For the ltrim() converter, on success, the area pointer of the sample buffer
is moved forward without updating the buffer size accordingly. If this
converter is followed by another one relying on the buffer size to do some
operations on the buffer area, this could lead to a buffer overflow.

Thanks to Charles Vosburgh <theminershive@gmail.com> for reporting this and
providing the fix.

This patch must be backported to all supported versions.

src/sample.c

index ff4cffb54960879be88fe246fe457778b54a76ee..b3dbd5ebcea606dab62f9f939035afc612a93e9e 100644 (file)
@@ -4510,6 +4510,8 @@ static int sample_conv_ltrim(const struct arg *arg_p, struct sample *smp, void *
                l--;
        }
 
+       if (smp->data.u.str.size)
+               smp->data.u.str.size -= p - smp->data.u.str.area;
        smp->data.u.str.area = p;
        smp->data.u.str.data = l;
        return 1;