From e8b3b4d3e42d32f0a27bdd22fa4a800f103c909b Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 15 Nov 2024 16:41:42 +0100 Subject: [PATCH] gnrc_pktbuf: assert that user count does not exceed 255 --- sys/net/gnrc/pktbuf_malloc/gnrc_pktbuf_malloc.c | 1 + sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c | 1 + 2 files changed, 2 insertions(+) diff --git a/sys/net/gnrc/pktbuf_malloc/gnrc_pktbuf_malloc.c b/sys/net/gnrc/pktbuf_malloc/gnrc_pktbuf_malloc.c index 683044adc0..9eb6335155 100644 --- a/sys/net/gnrc/pktbuf_malloc/gnrc_pktbuf_malloc.c +++ b/sys/net/gnrc/pktbuf_malloc/gnrc_pktbuf_malloc.c @@ -210,6 +210,7 @@ void gnrc_pktbuf_hold(gnrc_pktsnip_t *pkt, unsigned int num) { mutex_lock(&gnrc_pktbuf_mutex); while (pkt) { + assert(pkt->users + num <= 0xff); pkt->users += num; pkt = pkt->next; } diff --git a/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c b/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c index 3c98e8a61d..f1c15279c8 100644 --- a/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c +++ b/sys/net/gnrc/pktbuf_static/gnrc_pktbuf_static.c @@ -213,6 +213,7 @@ void gnrc_pktbuf_hold(gnrc_pktsnip_t *pkt, unsigned int num) { mutex_lock(&gnrc_pktbuf_mutex); while (pkt) { + assert(pkt->users + num <= 0xff); pkt->users += num; pkt = pkt->next; }