BUG/MINOR: h3: close connection on sending alloc errors
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 22 Dec 2023 08:00:13 +0000 (09:00 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 2 Jan 2024 07:29:10 +0000 (08:29 +0100)
commit6ff13aa4cd2086fb284234f7584599bfad3ecadb
tree7a1f576a392d680b8ec43d2ef967cc28923fa8c1
parentf50133bf30b1a3973f1b9f892786a7b19dca8aac
BUG/MINOR: h3: close connection on sending alloc errors

When encoding new HTTP/3 frames, QCS Tx buffer must be allocated if
currently NULL. Previously, allocation failure was not properly checked,
leaving the connection in an unspecified state, or worse risking a
crash.

Fix this by setting <h3c.err> to H3_INTERNAL_ERROR each time the
allocation fails. This will stop sending and close the connection. In
the future, it may be better to put the connection on pause waiting for
allocation to succeed but this is too complicated to implement for now
in a reliable way.

Along with the current change, return of all HTX parsing functions
(h3_resp_*_send) were set to a negative value in case of error. A new
BUG_ON() in h3_snd_buf() ensures that if such a value is returned,
either a connection error is register (via <h3c.err>) or buffer is
temporarily full (flag QC_SF_BLK_MROOM).

This should fix github issue #2389.

This should be backported up to 2.6. Note that qcc_get_stream_txbuf()
does not exist in 2.9 and below. mux_get_buf() is its equivalent. An
explicit check b_is_null(&qcs.tx.buf) should be used there.

(cherry picked from commit 2144d2418651c1f76b91cc1f6e745feecdefcb00)
[cf: H3_EV_TX_FRAME removed from trace messages because it does not exist]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/h3.c