From 312be239dfceff2f5bd8bc667701dda20af05c88 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Mon, 29 Jan 2024 14:39:19 +0100 Subject: [PATCH] BUG/MINOR: h3: fix checking on NULL Tx buffer 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 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 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/h3.c b/src/h3.c index ec061fc..1ffc76b 100644 --- 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; -- 1.7.10.4