In smp_fetch_body() and smp_fetch_body_param(), the defragmentation was
performed as soon as the HTX message was fragmented or unordered, or when
its free space was wrapping, without checking if the message had a payload.
In practice, it means a full HTX defragmentation was done for any bodyless
request or response when the HTX message was fragmented, which may happen
for instance after a header removal.
Now, the defragmentation is only performed if the message contains payload,
i.e. if the tail block type is higher than or equal to HTX_BLK_DATA. It is
not a strict check, but it is a cheap one, and messages with a single DATA
block never require a defragmentation anyway, since a single DATA block is
always contiguous.
This bug was introduced in 3.4 with the commit
ee309bafc ("MINOR:
http-fetch: Use pointer to HTX DATA block when retrieving HTX body"). It
must be backported as far as 3.4.
if (!htx)
return 0;
- if ((htx->flags & (HTX_FL_FRAGMENTED|HTX_FL_UNORDERED)) || htx_space_wraps(htx))
+ /* Only defrag if there is a payload */
+ if (htx_get_tail_type(htx) >= HTX_BLK_DATA &&
+ ((htx->flags & (HTX_FL_FRAGMENTED|HTX_FL_UNORDERED)) || htx_space_wraps(htx)))
htx_defrag(htx, NULL, 0);
for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
if (!htx)
return 0;
- if ((htx->flags & (HTX_FL_FRAGMENTED|HTX_FL_UNORDERED)) || htx_space_wraps(htx))
+ /* Only defrag if there is a payload */
+ if (htx_get_tail_type(htx) >= HTX_BLK_DATA &&
+ ((htx->flags & (HTX_FL_FRAGMENTED|HTX_FL_UNORDERED)) || htx_space_wraps(htx)))
htx_defrag(htx, NULL, 0);
for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {