BUG/MINOR: sample: fix concat() converter's corruption with non-string variables
authorWilly Tarreau <w@1wt.eu>
Fri, 8 Jan 2021 15:08:43 +0000 (16:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 8 Jan 2021 15:28:36 +0000 (16:28 +0100)
commit16f048c13af87e67a5d8afc42dc16754907696b6
tree14aa12c696e90cbb816fa50bc9cf3137e59ec633
parent7c512d2ba5aecb92a1e6a4a3ec09a387970730d9
BUG/MINOR: sample: fix concat() converter's corruption with non-string variables

Patrick Hemmer reported that calling concat() with an integer variable
causes a %00 to appear at the beginning of the output. Looking at the
code, it's not surprising. The function uses get_trash_chunk() to get
one of the trashes, but can call casting functions which will also use
their trash in turn and will cycle back to ours, causing the trash to
be overwritten before being assigned to a sample.

By allocating the trash from a pool using alloc_trash_chunk(), we can
avoid this. However we must free it so the trash's contents must be
moved to a permanent trash buffer before returning. This is what's
achieved using smp_dup().

This should be backported as far as 2.0.

(cherry picked from commit 591fc3a330005c289b4705fe4cb37c4eec9f9eed)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 79f4360bcbf4d4c4a56b7688dbb2cea839a5b9ba)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit 3d8ff18aaa8046d3e64a94d33c180db88c8033a0)
Signed-off-by: Willy Tarreau <w@1wt.eu>
src/sample.c