From: Dinko Korunic Date: Wed, 18 Nov 2026 17:05:05 +0000 (+0100) Subject: BUG/MINOR: payload: also encode an absolute payload_lv offset2 X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/gitweb.js?a=commitdiff_plain;h=3a69eb799b0c2a8a78454398401395930d8cc9f0;p=haproxy.git 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. --- diff --git a/src/payload.c b/src/payload.c index 3c5e0bcb8..be722563c 100644 --- a/src/payload.c +++ b/src/payload.c @@ -1279,8 +1279,8 @@ int val_payload_lv(struct arg *arg, char **err_msg) memprintf(err_msg, "payload offset2 too large"); return 0; } - if (relative) - arg[2].data.sint = ( arg[2].data.sint << 1 ) + 1; + /* the fetch reads the offset from the 63 MSB, see above */ + arg[2].data.sint = (arg[2].data.sint << 1) + relative; } return 1; }