From 1cd19b309e382d1d2693cf7e0503c37eaefb345e Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Tue, 20 Oct 2026 16:18:19 +0300 Subject: [PATCH] iscsi-scstd: Share ARRAY_SIZE for userspace dispatch bounds Coccinelle misc/array_size.cocci reports: iscsi-scst/usr/iscsi_adm.c:595:33-34: WARNING: Use ARRAY_SIZE Move the existing iSNS ARRAY_SIZE helper to misc.h and use it for the user-command dispatch table in iscsi-scst-adm. Both users already include that header, so they can share the definition. Preserve the size_t comparison, including rejection of negative operation values, and the unsupported-operation path. The table index is used only after the bounds check succeeds. --- iscsi-scst/usr/iscsi_adm.c | 4 ++-- iscsi-scst/usr/isns.c | 1 - iscsi-scst/usr/misc.h | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iscsi-scst/usr/iscsi_adm.c b/iscsi-scst/usr/iscsi_adm.c index 19af94727..eb3683317 100644 --- a/iscsi-scst/usr/iscsi_adm.c +++ b/iscsi-scst/usr/iscsi_adm.c @@ -592,8 +592,8 @@ static int user_handle(int op, u32 set, u32 tid, char *params) if (err) goto out; - if ((op >= sizeof(user_handle_fn)/sizeof(user_handle_fn[0])) || - ((fn = user_handle_fn[op]) == NULL)) { + fn = op < ARRAY_SIZE(user_handle_fn) ? user_handle_fn[op] : NULL; + if (!fn) { fprintf(stderr, "Unsupported\n"); goto out; } diff --git a/iscsi-scst/usr/isns.c b/iscsi-scst/usr/isns.c index 323e00c53..96ea65594 100644 --- a/iscsi-scst/usr/isns.c +++ b/iscsi-scst/usr/isns.c @@ -34,7 +34,6 @@ #include "isns_proto.h" #include "misc.h" -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define BUFSIZE (1 << 18) struct isns_io { diff --git a/iscsi-scst/usr/misc.h b/iscsi-scst/usr/misc.h index 89f9aba36..ca46150ed 100644 --- a/iscsi-scst/usr/misc.h +++ b/iscsi-scst/usr/misc.h @@ -16,6 +16,8 @@ #ifndef MISC_H #define MISC_H +#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) + struct __qelem { struct __qelem *q_forw; struct __qelem *q_back;