From: Christopher Faulet Date: Mon, 27 Jul 2026 10:10:49 +0000 (+0200) Subject: BUG/MINOR: htx: Perform raw copy for messages of same size in htx_copy_msg() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b4feec60ba44404b104fbeade08b155279cf0f55;p=thirdparty%2Fhaproxy.git BUG/MINOR: htx: Perform raw copy for messages of same size in htx_copy_msg() htx_copy_msg() takes a shortcut when the destination message is empty and copies the whole source area, HTX header included, in one memcpy(): if (htx_is_empty(htx) && htx_free_space(htx)) { memcpy(htx, msg->area, msg->size); return 1; } but it never verifies that the destination buffer is at least as large as size>. The only caller, http_reply_to_htx(), copies an error message buffer, which http_str_to_htx() always allocates with a size of global.tune.bufsize, into the response channel buffer. Two things follow: - if the destination were smaller, this would be a plain heap overflow. It is not reachable today because the response channel buffer is never a small one: only the request channel may be moved to a small buffer, by the PR_O2_USE_SBUF_QUEUE code in stream.c, and the L7-retry buffer is not a channel. But nothing states nor checks that invariant, and small buffers are recent, so this is a landmine. - if the destination is larger, which does happen since "http-response wait-for-body