]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: h1: fix detection of upper bytes in the URI
authorWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2024 09:37:06 +0000 (11:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 24 Apr 2024 09:50:36 +0000 (11:50 +0200)
commitb9bf16b3827c58e61bf4cf27b30e14484fd2b6e5
treeda6e33046851ad228853d68d6725b91e08d36855
parent98d22f212a24cc10e358e0f311e715a5bbbe2e96
BUG/MINOR: h1: fix detection of upper bytes in the URI

In 1.7 with commit 5f10ea30f4 ("OPTIM: http: improve parsing performance
of long URIs") we improved the URI parser's performance on platforms
supporting unaligned accesses by reading 4 chars at a time in a 32-bit
word. However, as reported in GH issue #2545, there's a bug in the way
the top bytes are checked, as the parser will stop when all 4 of them
are above 7e instead of when one of them is, so certain patterns can be
accepted through if the last ones are all valid. The fix requires to
negate the value but on the other hand it allows to parallelize some of
the tests and fuse the masks, which could even end up slightly faster.

This needs to be backported to all stable versions, but be careful, this
code moved a lot over time, from proto_http.c to h1.c, to http_msg.c, to
h1.c again. Better just grep for "24242424" or "21212121" in each version
to find it.

Big kudos to Martijn van Oosterhout (@kleptog) for spotting this problem
while analyzing that piece of code, and reporting it.
src/h1.c