From ab55b1107a9090d8871a69a3e66a16fcf2c2d6f6 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Menaldo" Date: Sat, 3 Aug 2024 01:34:09 -0300 Subject: [PATCH 1/2] Add assertion to ensure MAX_PACKET_DB is valid --- src/common/packets.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/packets.h b/src/common/packets.h index a4dea570a07..e1aecfd3bae 100644 --- a/src/common/packets.h +++ b/src/common/packets.h @@ -30,6 +30,8 @@ #define MAX_PACKET_DB 0x0F00 #endif +STATIC_ASSERT(MAX_PACKET_DB <= USHRT_MAX, "MAX_PACKET_DB must not exceed 2 bytes (USHRT_MAX / 65,535)"); + #ifndef MIN_INTIF_PACKET_DB #define MIN_INTIF_PACKET_DB 0x3800 #endif From 81ad9712fa981cb18e80cfbea529c27dda9bc7c5 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Menaldo" Date: Sat, 3 Aug 2024 01:35:34 -0300 Subject: [PATCH 2/2] Add alert when plugins defines packets out of the accepted range this makes addPacket macro for HPM plugins to properly alert users when their packets are ignored due to being out of the supported range, this was previously silently ignored --- src/common/HPM.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/HPM.c b/src/common/HPM.c index 9608eec218e..3fc3c04a8d8 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -190,6 +190,9 @@ static bool hplugins_addpacket(unsigned short cmd, unsigned short length, void ( if (cmd <= MAX_PACKET_DB && cmd >= MIN_PACKET_DB) { packets->db[cmd] = length; + } else { + ShowError("HPM->addPacket:%s: packet 0x%04x is out of range! Packet ID must be between 0x%04x (MIN_PACKET_DB) and 0x%04x (MAX_PACKET_DB). Ignoring it...\n", + HPM->pid2name(pluginID), cmd, (unsigned int) MIN_PACKET_DB, (unsigned int) MAX_PACKET_DB); } return true;