]> git.kaiwu.me - haproxy.git/commit
BUG/MINOR: payload: also encode an absolute payload_lv offset2
authorDinko Korunic <dkorunic@haproxy.com>
Wed, 18 Nov 2026 17:05:05 +0000 (18:05 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Nov 2026 07:21:06 +0000 (08:21 +0100)
commit3a69eb799b0c2a8a78454398401395930d8cc9f0
tree1e9bb61a18ec755fe9b93b5c4a49e25e5d76c65b
parent715ff9dc90da2315a5286a11c80a86bbb5cfa637
BUG/MINOR: payload: also encode an absolute payload_lv offset2

Since commit bf65cd4d77 ("MAJOR: arg: converts uint and sint in sint")
in 1.6-dev3, the optional offset2 of payload_lv is stored as a single
SINT whose LSB indicates a relative offset and whose 63 MSB carry the
value, and smp_fetch_payload_lv() decodes it this way. But
val_payload_lv() only encodes relative values as "(v << 1) + 1" and
leaves absolute ones untouched. An absolute offset2 is thus read as half
of its value, and an odd one is even taken as a relative offset. With a
payload starting with "01 41 42 43 44 45":

    req.payload_lv(0,1,4)   returns 0x42 instead of 0x44
    req.payload_lv(0,1,5)   behaves like (0,1,+2), returns 0x43
                            instead of 0x45

This only affects which bytes are extracted: the resulting offset is
still checked against the buffer by the fetch function, so there is no
memory-safety impact. Configurations using an absolute offset2 were
silently reading from the wrong place and will now read from the
documented one.

Let's always encode offset2, adding the relative flag as the LSB. Relative
and implicit offsets are not affected.

This depends on the previous commit "BUG/MEDIUM: payload: reject
out-of-range payload and payload_lv arguments" for its context, and
should be backported to all supported versions along with it.
src/payload.c