ubusd: fix txq_len accounting
authorFelix Fietkau <nbd@nbd.name>
Tue, 1 Jul 2025 18:34:25 +0000 (20:34 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 1 Jul 2025 18:34:26 +0000 (20:34 +0200)
Track the header size in order to avoid underflow

Signed-off-by: Felix Fietkau <nbd@nbd.name>
ubusd.c

diff --git a/ubusd.c b/ubusd.c
index 1d76b72e42867de81f2527bc288bc017535b5f0b..5aebce535cbf514625295d387e857a66382f0e5d 100644 (file)
--- a/ubusd.c
+++ b/ubusd.c
@@ -144,7 +144,7 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub)
 {
        struct ubus_msg_buf_list *ubl;
 
-       if (cl->txq_len + ub->len > UBUS_CLIENT_MAX_TXQ_LEN)
+       if (cl->txq_len + sizeof(ub->hdr) + ub->len > UBUS_CLIENT_MAX_TXQ_LEN)
                return;
 
        ubl = calloc(1, sizeof(struct ubus_msg_buf_list));
@@ -155,7 +155,7 @@ static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub)
        ubl->msg = ubus_msg_ref(ub);
 
        list_add_tail(&ubl->list, &cl->tx_queue);
-       cl->txq_len += ub->len;
+       cl->txq_len += ub->len + sizeof(ub->hdr);
 }
 
 /* takes the msgbuf reference */