]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: sample: Fix adjusting size in field converter
authorThayne McCombs <astrothayne@gmail.com>
Mon, 12 Apr 2021 05:26:59 +0000 (23:26 -0600)
committerWilly Tarreau <w@1wt.eu>
Tue, 13 Apr 2021 10:12:48 +0000 (12:12 +0200)
Adjust the size of the sample buffer before we change the "area"
pointer. The change in size is calculated as the difference between the
original pointer and the new start pointer. But since the
`smp->data.u.str.area` assignment results in `smp->data.u.str.area` and
`start` being the same pointer, we always ended up substracting zero.
This changes it to change the size by the actual amount it changed.

I'm not entirely sure what the impact of this is, but the previous code
seemed wrong.

[wt: from what I can see the only harmful case is when the output is
 converted to a stick-table key, it could result in zeroing past the
 end of the buffer; other cases do not touch beyond ->data]

src/sample.c

index 835a181156568e86727e36dbd59bb0b3dd3d503f..0c0f36ec52aaf70d2d4b648c3b6ac2090077edae 100644 (file)
@@ -2561,13 +2561,13 @@ found:
        if (!smp->data.u.str.data)
                return 1;
 
-       smp->data.u.str.area = start;
-
        /* Compute remaining size if needed
            Note: smp->data.u.str.size cannot be set to 0 */
        if (smp->data.u.str.size)
                smp->data.u.str.size -= start - smp->data.u.str.area;
 
+       smp->data.u.str.area = start;
+
        return 1;
 }