From 747ee9d56f2324658a681917297487506556f1a9 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Tue, 22 Nov 2022 13:27:41 +0100 Subject: [PATCH] sys/net/grnc/netreg: avoid freeing wild pointers When freeing any stale pktsnips from stale messages in the mbox, make sure that the messages actually contains a pktsnip before freeing. --- sys/net/gnrc/netreg/gnrc_netreg.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/net/gnrc/netreg/gnrc_netreg.c b/sys/net/gnrc/netreg/gnrc_netreg.c index 556b6bc49a75..bf26713ac175 100644 --- a/sys/net/gnrc/netreg/gnrc_netreg.c +++ b/sys/net/gnrc/netreg/gnrc_netreg.c @@ -177,7 +177,10 @@ void gnrc_netreg_unregister(gnrc_nettype_t type, gnrc_netreg_entry_t *entry) if (entry->type == GNRC_NETREG_TYPE_MBOX) { msg_t msg; while (mbox_try_get(entry->target.mbox, &msg)) { - gnrc_pktbuf_release_error(msg.content.ptr, EBADF); + if ((msg.type == GNRC_NETAPI_MSG_TYPE_RCV) || + (msg.type == GNRC_NETAPI_MSG_TYPE_SND)) { + gnrc_pktbuf_release_error(msg.content.ptr, EBADF); + } } } #endif