BUG/MINOR: h3: fix checking on NULL Tx buffer
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 29 Jan 2024 13:39:19 +0000 (14:39 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 29 Jan 2024 13:44:50 +0000 (14:44 +0100)
The following patch was backported to handle gracefully Tx buffer
allocation failure.

  BUG/MINOR: h3: close connection on sending alloc errors

However, the backport is not correct. Indeed, mux_get_buf() returns a
pointer to <qcs.tx.buf> field which is always true. Instead, an explicit
check using b_is_null() must be done instead.

This must be backported up to 2.6.

src/h3.c

index ec061fc..1ffc76b 100644 (file)
--- a/src/h3.c
+++ b/src/h3.c
@@ -1471,7 +1471,7 @@ static int h3_control_send(struct qcs *qcs, void *ctx)
        }
 
        res = mux_get_buf(qcs);
-       if (!res) {
+       if (b_is_null(res)) {
                TRACE_ERROR("cannot allocate Tx buffer", H3_EV_TX_SETTINGS, qcs->qcc->conn, qcs);
                goto err;
        }
@@ -1554,7 +1554,7 @@ static int h3_resp_headers_send(struct qcs *qcs, struct htx *htx)
        list[hdr].n = ist("");
 
        res = mux_get_buf(qcs);
-       if (!res) {
+       if (b_is_null(res)) {
                TRACE_ERROR("cannot allocate Tx buffer", H3_EV_TX_HDR, qcs->qcc->conn, qcs);
                h3c->err = H3_INTERNAL_ERROR;
                goto err;
@@ -1695,7 +1695,7 @@ static int h3_resp_trailers_send(struct qcs *qcs, struct htx *htx)
        list[hdr].n = ist("");
 
        res = mux_get_buf(qcs);
-       if (!res) {
+       if (b_is_null(res)) {
                TRACE_ERROR("cannot allocate Tx buffer", H3_EV_TX_HDR, qcs->qcc->conn, qcs);
                h3c->err = H3_INTERNAL_ERROR;
                goto err;
@@ -1811,7 +1811,7 @@ static int h3_resp_data_send(struct qcs *qcs, struct buffer *buf, size_t count)
                goto end;
 
        res = mux_get_buf(qcs);
-       if (!res) {
+       if (b_is_null(res)) {
                TRACE_ERROR("cannot allocate Tx buffer", H3_EV_TX_DATA, qcs->qcc->conn, qcs);
                h3c->err = H3_INTERNAL_ERROR;
                goto err;
@@ -2012,7 +2012,7 @@ static size_t h3_nego_ff(struct qcs *qcs, size_t count)
        h3_debug_printf(stderr, "%s\n", __func__);
 
        res = mux_get_buf(qcs);
-       if (!res) {
+       if (b_is_null(res)) {
                qcs->sd->iobuf.flags |= IOBUF_FL_NO_FF;
                goto end;
        }
@@ -2234,7 +2234,7 @@ static int h3_send_goaway(struct h3c *h3c)
        b_quic_enc_int(&pos, h3c->id_goaway, 0);
 
        res = mux_get_buf(qcs);
-       if (!res || b_room(res) < b_data(&pos)) {
+       if (b_is_null(res) || b_room(res) < b_data(&pos)) {
                /* Do not try forcefully to emit GOAWAY if no space left. */
                TRACE_ERROR("cannot send GOAWAY", H3_EV_H3C_END, h3c->qcc->conn, qcs);
                goto err;