From fdc16c1e01fc7fcf4479043c71e7a54cf49a6bc9 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 1 Oct 2024 10:55:40 +0200 Subject: [PATCH] MINOR: quic: ensure txbuf realloc is only performed on empty buffer QUIC application protocol layer has the ability to either allocate a standard buffer or a smaller one. The latter is useful when only small data are transferred to prevent consuming too much of the QUIC MUX buffer window. This operation is performed using qc_stream_buf_realloc(). Add a new BUG_ON() in it to ensure no data is present in the buffer. Indeed, this would cause to data loss, or even crash when trying to acknowledge data. Note that for the moment qc_stream_buf_realloc() is only use for HTTP/3 headers transmission, and this usage is conform to the new BUG_ON. This commit is thus not a bug fix, but only to strengthen the API. --- src/quic_stream.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/quic_stream.c b/src/quic_stream.c index bf9a54e62..7181e0034 100644 --- a/src/quic_stream.c +++ b/src/quic_stream.c @@ -325,6 +325,9 @@ struct buffer *qc_stream_buf_realloc(struct qc_stream_desc *stream) /* This function is reserved to convert a big buffer to a smaller one. */ BUG_ON(!stream->buf || !stream->buf->sbuf); + /* This function can only be used if targetted buffer is empty. */ + BUG_ON(b_data(&stream->buf->buf)); + /* Release buffer */ pool_free(pool_head_sbuf, stream->buf->buf.area); stream->buf->buf = BUF_NULL;