Skip to content

Commit

Permalink
RDMA/rtrs-clt: Check strnlen return len in sysfs mpath_policy_store()
Browse files Browse the repository at this point in the history
strnlen() may return 0 (e.g. for "\0\n" string), it's better to
check the result of strnlen() before using 'len - 1' expression
for the 'buf' array index.

Detected using the static analysis tool - Svace.

Fixes: dc3b66a ("RDMA/rtrs-clt: Add a minimum latency multipath policy")
Signed-off-by: Alexey Kodanev <aleksei.kodanev@bell-sw.com>
Link: https://lore.kernel.org/r/20240221113204.147478-1-aleksei.kodanev@bell-sw.com
Acked-by: Jack Wang <jinpu.wang@ionos.com>
Signed-off-by: Leon Romanovsky <leon@kernel.org>
  • Loading branch information
Alexey Kodanev authored and Leon Romanovsky committed Feb 25, 2024
1 parent 14b526f commit 7a7b7f5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static ssize_t mpath_policy_store(struct device *dev,

/* distinguish "mi" and "min-latency" with length */
len = strnlen(buf, NAME_MAX);
if (buf[len - 1] == '\n')
if (len && buf[len - 1] == '\n')
len--;

if (!strncasecmp(buf, "round-robin", 11) ||
Expand Down

0 comments on commit 7a7b7f5

Please sign in to comment.