Skip to content

Commit 7a7b7f5

Browse files
akodanevrleon
authored andcommitted
RDMA/rtrs-clt: Check strnlen return len in sysfs mpath_policy_store()
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Jack Wang <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent 14b526f commit 7a7b7f5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static ssize_t mpath_policy_store(struct device *dev,
133133

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

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

0 commit comments

Comments
 (0)