BUG/MAJOR: htx: Fix htx_defrag() when an HTX block is expanded
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 9 Jun 2021 15:30:40 +0000 (17:30 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 11 Jun 2021 12:05:34 +0000 (14:05 +0200)
commit1cf414b522b465c97e5e87e4e38be93e6f634b32
tree22ffb991f1f8e984f1825e220df14cea36523888
parent00613231149b6f92807157b578d72fad0ca00f7d
BUG/MAJOR: htx: Fix htx_defrag() when an HTX block is expanded

When an HTX block is expanded, a defragmentation may be performed first to
have enough space to copy the new data. When it happens, the meta data of
the HTX message must take account of the new data length but copied data are
still unchanged at this stage (because we need more space to update the
message content). And here there is a bug because the meta data are updated
by the caller. It means that when the blocks content is copied, the new
length is already set. Thus a block larger than the reality is copied and
data outside the buffer may be accessed, leading to a crash.

To fix this bug, htx_defrag() is updated to use an extra argument with the
new meta data to use for the referenced block. Thus the caller does not need
to update the HTX message by itself. However, it still have to update the
data.

Most of time, the bug will be encountered in the HTTP compression
filter. But, even if it is highly unlikely, in theory it is also possible to
hit it when a HTTP header (or only its value) is replaced or when the
start-line is changed.

This patch must be backported as far as 2.0.
include/haproxy/htx.h
src/htx.c