diff options
author | Alexey Kodanev <aleksei.kodanev@bell-sw.com> | 2024-02-21 11:32:04 +0000 |
---|---|---|
committer | Leon Romanovsky <leon@kernel.org> | 2024-02-25 18:21:42 +0200 |
commit | 7a7b7f575a25aa68ee934ee8107294487efcb3fe (patch) | |
tree | 83ea028cc054c3d7d6f5f87c7129a6e93388cca0 /drivers/infiniband/ulp | |
parent | 14b526f55ba5916856126f9793309fd6de5c5e7e (diff) | |
download | linux-stable-7a7b7f575a25aa68ee934ee8107294487efcb3fe.tar.gz linux-stable-7a7b7f575a25aa68ee934ee8107294487efcb3fe.tar.bz2 linux-stable-7a7b7f575a25aa68ee934ee8107294487efcb3fe.zip |
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: dc3b66a0ce70 ("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>
Diffstat (limited to 'drivers/infiniband/ulp')
-rw-r--r-- | drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c index d3c436ead694..4aa80c9388f0 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt-sysfs.c @@ -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) || |