]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: htx: Properly handle block modification during defragmentation
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 13 Apr 2026 17:07:08 +0000 (19:07 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 14 Apr 2026 12:07:21 +0000 (14:07 +0200)
A regression was introcuded by the commit 0c6f2207f ("MEDIUM: htx: Refactor
htx defragmentation to merge data blocks").

When a defragmentation is performed, it is possible to alter a block
size. The main usage is to prepare a block value replacement. However, since
the commit above, the change is no longer handled. The block info are
changed but the size of the message is not modified accordingly.

This patch depends on the commit "MINOR: htx: Add helper function to get
type and size from the block info field"

No backport needed.

src/htx.c

index e5cbc80dcabc1c28cfdbeb96acb8029a5e6cc1e3..6ace1d3e8d7c175a7ec32946e3326a9cb9d86573 100644 (file)
--- a/src/htx.c
+++ b/src/htx.c
@@ -72,8 +72,14 @@ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk, uint32_t blkinf
                                }
                                __fallthrough;
                        default:
-                               newblk = htx_add_blk(tmp, type, blksz);
-                               newblk->info = oldblk->info;
+                               if (blk == oldblk && blkinfo) {
+                                       newblk = htx_add_blk(tmp, type, __htx_blkinfo_size(blkinfo));
+                                       newblk->info = blkinfo;
+                               }
+                               else {
+                                       newblk = htx_add_blk(tmp, type, blksz);
+                                       newblk->info = oldblk->info;
+                               }
                                htx_memcpy(htx_get_blk_ptr(tmp, newblk), htx_get_blk_ptr(htx, oldblk), blksz);
                                break;
                };
@@ -83,15 +89,13 @@ struct htx_blk *htx_defrag(struct htx *htx, struct htx_blk *blk, uint32_t blkinf
                        tmp->first = new;
 
                /* if <blk> is defined, save its new position */
-               if (blk != NULL && blk == oldblk) {
-                       if (blkinfo)
-                               newblk->info = blkinfo;
+               if (blk == oldblk)
                        blkpos = new;
-               }
+
                new++;
        }
 
-       BUG_ON(htx->data != tmp->data);
+       htx->data = tmp->data;
        htx->first = tmp->first;
        htx->head = tmp->head;
        htx->tail = tmp->tail;