From 9320bc242ad489d81f236c2365cf8897757dbab9 Mon Sep 17 00:00:00 2001 From: Vyacheslav Yamont Date: Mon, 19 Jan 2026 00:29:43 +0100 Subject: [PATCH] Stpctl derive command list size from array Switch command list iteration to use sizeof(g_cmd_list) instead of STP_CTL_MAX, preventing potential out-of-bounds access if the enum and list diverge. Signed-off-by: Vyacheslav Yamont --- stpctl/stpctl.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stpctl/stpctl.c b/stpctl/stpctl.c index 4d6f28a..df85c86 100644 --- a/stpctl/stpctl.c +++ b/stpctl/stpctl.c @@ -16,7 +16,6 @@ */ #include "stpctl.h" -#define cmd_max STP_CTL_MAX CMD_LIST g_cmd_list[] = { "help", STP_CTL_HELP, "all", STP_CTL_DUMP_ALL, @@ -36,20 +35,22 @@ CMD_LIST g_cmd_list[] = { "mstport", STP_CTL_DUMP_MST_PORT, }; +#define CMD_LIST_COUNT (sizeof(g_cmd_list) / sizeof(g_cmd_list[0])) + void print_cmds() { - int i; + size_t i; - for (i=0; i