mirror of
https://github.com/SCST-project/scst.git
synced 2026-10-22 06:02:33 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user