Hi, Here are two small fixes for the net_helper converters, against current master (f16798587). The patches are attached (git format-patch); the code changes are independent, but 2/2 applies on top of 1/2 since it extends the reg-test that 1/2 adds.
1/2 BUG/MINOR: net_helper: check the TCP option length before reading its value tcp.options.mss, tcp.options.tsval and tcp.options.wscale read the value without checking the option's length field, so a short option makes them return the bytes that follow it. With a 24-byte header ending with "NOP NOP 02 02" and the payload 0x12 0x34, tcp.options.mss returns 4660; with "NOP NOP 03 02" and 0xaa, tcp.options.wscale returns 170. When nothing follows the header, the value is read past the end of the sample. The client chooses its SYN options, so these values come from the client. The patch makes these converters ignore an option whose length is not the defined one (4, 10 and 3), as if it were absent. 2/2 BUG/MINOR: net_helper: accept an Ethernet header ending with the protocol The eth.* loops use "idx + 2 < data", so an input that ends right after the protocol field is reported as incomplete: "eth.hdr,eth.proto" and "eth.hdr,eth.vlan" return nothing. The patch uses "<=". 1/2 adds reg-tests/converter/net_helper.vtc, and 2/2 extends it. The test fails on master (mss-len2 (4660) == "0") and with only 1/2 applied (eth-hdr-proto () == "2048"), and passes with both; the other converter reg-tests still pass (26 passed, 6 skipped). Both should be backported to 3.4. Found by an LLM-assisted tool, verified manually. Regards, Martin Mirchev
From 61c6c473b30d9fe5e7b93e2c1a2e90be0bd71c4b Mon Sep 17 00:00:00 2001 From: Martin Mirchev <[email protected]> Date: Wed, 18 Nov 2026 11:25:19 +0800 Subject: [PATCH 1/2] BUG/MINOR: net_helper: check the TCP option length before reading its value tcp_fullhdr_find_opt() only checks that an option fits in the TCP header and has a length of at least 2, so the tcp.options.mss, tcp.options.tsval and tcp.options.wscale converters read their value from the bytes that follow the option when its length field is too small. With a 24-byte header ending with "NOP NOP 02 02" followed by the payload 0x12 0x34, tcp.options.mss returns 4660, and with "NOP NOP 03 02" followed by 0xaa, tcp.options.wscale returns 170. When the option is the last one and nothing follows the header, the value is read past the end of the input sample (by up to 4 bytes for tsval). This patch makes these 3 converters ignore the option when its length is not the one defined for it (4 for MSS, 10 for TimeStamp, 3 for Window Scale), as when the option is absent, so that they return 0 in this case. A new reg-test, reg-tests/converter/net_helper.vtc, checks these cases. This should be backported to 3.4. --- reg-tests/converter/net_helper.vtc | 40 ++++++++++++++++++++++++++++++ src/net_helper.c | 12 +++++++++ 2 files changed, 52 insertions(+) create mode 100644 reg-tests/converter/net_helper.vtc diff --git a/reg-tests/converter/net_helper.vtc b/reg-tests/converter/net_helper.vtc new file mode 100644 index 000000000..85d6450cb --- /dev/null +++ b/reg-tests/converter/net_helper.vtc @@ -0,0 +1,40 @@ +varnishtest "net_helper converters Test" + +feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(3.4-dev0)'" +feature ignore_unknown_macro + +haproxy h1 -conf { + global + .if feature(THREAD) + thread-groups 1 + .endif + + defaults + mode http + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + + frontend fe + bind "fd@${fe}" + + # 24-byte TCP headers: 20 bytes followed by 4 bytes of options, + # then possibly some payload. + http-request return status 200 + http-after-response set-header mss-ok "%[bin(00010050000000000000000060020000ffff000002040578),tcp.options.mss]" + http-after-response set-header mss-len2 "%[bin(00010050000000000000000060020000ffff0000010102021234),tcp.options.mss]" + http-after-response set-header ws-ok "%[bin(00010050000000000000000060020000ffff000001030307),tcp.options.wscale]" + http-after-response set-header ws-len2 "%[bin(00010050000000000000000060020000ffff000001010302aa),tcp.options.wscale]" + http-after-response set-header tsval-len2 "%[bin(00010050000000000000000060020000ffff00000101080212345678),tcp.options.tsval]" +} -start + +client c1 -connect ${h1_fe_sock} { + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.mss-ok == "1400" + expect resp.http.mss-len2 == "0" + expect resp.http.ws-ok == "7" + expect resp.http.ws-len2 == "0" + expect resp.http.tsval-len2 == "0" +} -run diff --git a/src/net_helper.c b/src/net_helper.c index 4cfa457cb..6a0c7d7d3 100644 --- a/src/net_helper.c +++ b/src/net_helper.c @@ -499,6 +499,10 @@ static int sample_conv_tcp_options_mss(const struct arg *arg_p, struct sample *s if (!len) return 0; + /* the MSS option is always 4 bytes long */ + if (ofs && (uchar)smp->data.u.str.area[ofs + 1] != 4) + ofs = 0; + smp->data.u.sint = ofs ? read_n16(smp->data.u.str.area + ofs + 2) : 0; smp->data.type = SMP_T_SINT; smp->flags &= ~SMP_F_CONST; @@ -551,6 +555,10 @@ static int sample_conv_tcp_options_tsval(const struct arg *arg_p, struct sample if (!len) return 0; + /* the TimeStamp option is always 10 bytes long */ + if (ofs && (uchar)smp->data.u.str.area[ofs + 1] != 10) + ofs = 0; + smp->data.u.sint = ofs ? read_n32(smp->data.u.str.area + ofs + 2) : 0; smp->data.type = SMP_T_SINT; smp->flags &= ~SMP_F_CONST; @@ -569,6 +577,10 @@ static int sample_conv_tcp_options_wscale(const struct arg *arg_p, struct sample if (!len) return 0; + /* the Window Scale option is always 3 bytes long */ + if (ofs && (uchar)smp->data.u.str.area[ofs + 1] != 3) + ofs = 0; + smp->data.u.sint = ofs ? (uchar)smp->data.u.str.area[ofs + 2] : 0; smp->data.type = SMP_T_SINT; smp->flags &= ~SMP_F_CONST; -- 2.50.1
From 6093e206488bb27be8b337eea503df97761a1dae Mon Sep 17 00:00:00 2001 From: Martin Mirchev <[email protected]> Date: Wed, 18 Nov 2026 11:25:34 +0800 Subject: [PATCH 2/2] BUG/MINOR: net_helper: accept an Ethernet header ending with the protocol The eth.data, eth.hdr, eth.proto and eth.vlan converters walk the Ethernet header with "idx + 2 < data", which requires at least one byte after the 2-byte protocol field. An input that ends exactly with the header is thus reported as incomplete, so eth.proto and eth.vlan return nothing on the output of eth.hdr: "eth.hdr,eth.proto" never works, and neither does any frame truncated right after the protocol field. The protocol field is complete when idx + 2 <= data, so let's use this condition in the 4 loops. Frames that carry data after the header are not affected. The net_helper reg-test now checks eth.hdr followed by eth.proto and eth.vlan. This should be backported to 3.4. --- reg-tests/converter/net_helper.vtc | 13 +++++++++++++ src/net_helper.c | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/reg-tests/converter/net_helper.vtc b/reg-tests/converter/net_helper.vtc index 85d6450cb..7fc8bb824 100644 --- a/reg-tests/converter/net_helper.vtc +++ b/reg-tests/converter/net_helper.vtc @@ -26,6 +26,14 @@ haproxy h1 -conf { http-after-response set-header ws-ok "%[bin(00010050000000000000000060020000ffff000001030307),tcp.options.wscale]" http-after-response set-header ws-len2 "%[bin(00010050000000000000000060020000ffff000001010302aa),tcp.options.wscale]" http-after-response set-header tsval-len2 "%[bin(00010050000000000000000060020000ffff00000101080212345678),tcp.options.tsval]" + + # Ethernet header with one VLAN tag (ID 100) and IPv4, followed by + # some data, and the same header alone as returned by eth.hdr. + http-after-response set-header eth-proto "%[bin(000000000000000000000000810000640800450000),eth.proto]" + http-after-response set-header eth-hdr-proto "%[bin(000000000000000000000000810000640800450000),eth.hdr,eth.proto]" + http-after-response set-header eth-hdr-vlan "%[bin(000000000000000000000000810000640800450000),eth.hdr,eth.vlan]" + http-after-response set-header eth-data "%[bin(000000000000000000000000810000640800450000),eth.data,hex]" + http-after-response set-header eth-noproto "%[bin(00000000000000000000000081000064),eth.proto]" } -start client c1 -connect ${h1_fe_sock} { @@ -37,4 +45,9 @@ client c1 -connect ${h1_fe_sock} { expect resp.http.ws-ok == "7" expect resp.http.ws-len2 == "0" expect resp.http.tsval-len2 == "0" + expect resp.http.eth-proto == "2048" + expect resp.http.eth-hdr-proto == "2048" + expect resp.http.eth-hdr-vlan == "100" + expect resp.http.eth-data == "450000" + expect resp.http.eth-noproto == "" } -run diff --git a/src/net_helper.c b/src/net_helper.c index 6a0c7d7d3..e9a062b67 100644 --- a/src/net_helper.c +++ b/src/net_helper.c @@ -23,7 +23,7 @@ static int sample_conv_eth_data(const struct arg *arg_p, struct sample *smp, voi { size_t idx; - for (idx = 12; idx + 2 < smp->data.u.str.data; idx += 4) { + for (idx = 12; idx + 2 <= smp->data.u.str.data; idx += 4) { if (read_n16(smp->data.u.str.area + idx) != 0x8100) { if (smp->data.u.str.size) smp->data.u.str.size -= idx + 2; @@ -54,7 +54,7 @@ static int sample_conv_eth_hdr(const struct arg *arg_p, struct sample *smp, void { size_t idx; - for (idx = 12; idx + 2 < smp->data.u.str.data; idx += 4) { + for (idx = 12; idx + 2 <= smp->data.u.str.data; idx += 4) { if (read_n16(smp->data.u.str.area + idx) != 0x8100) { smp->data.u.str.data = idx + 2; return 1; @@ -72,7 +72,7 @@ static int sample_conv_eth_proto(const struct arg *arg_p, struct sample *smp, vo ushort proto; size_t idx; - for (idx = 12; idx + 2 < smp->data.u.str.data; idx += 4) { + for (idx = 12; idx + 2 <= smp->data.u.str.data; idx += 4) { proto = read_n16(smp->data.u.str.area + idx); if (proto != 0x8100) { smp->data.u.sint = proto; @@ -107,7 +107,7 @@ static int sample_conv_eth_vlan(const struct arg *arg_p, struct sample *smp, voi ushort vlan = 0; size_t idx; - for (idx = 12; idx + 2 < smp->data.u.str.data; idx += 4) { + for (idx = 12; idx + 2 <= smp->data.u.str.data; idx += 4) { if (read_n16(smp->data.u.str.area + idx) != 0x8100) { smp->data.u.sint = vlan; smp->data.type = SMP_T_SINT; -- 2.50.1

