From: Sebastien Buisson Date: Mon, 16 Dec 2024 20:04:56 +0000 (+0100) Subject: LU-18571 nodemap: fix coverity issues in range_create() X-Git-Tag: 2.16.51~2 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=6fdb04e86a02a789785c59606e38c2ff9d4358c7;p=fs%2Flustre-release.git LU-18571 nodemap: fix coverity issues in range_create() Fix issues found by Coverity in range_create(): CoverityID: 451797 ("Null pointer dereferences") Dereferencing a pointer that might be "NULL" "c" when calling "strscpy". CoverityID: 451795 ("Integer handling issues") "netmask > 999" is always false regardless of the values of its operands. This occurs as the logical operand of "if." Fixes: 8f6988be44 ("LU-14288 nodemap: Use nidmasks for IPv6 NIDs") Signed-off-by: Sebastien Buisson Change-Id: I1a6f85f2c9a3591ddd82ed634e9a87902b2b7d0a Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57488 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Chris Horn Reviewed-by: Oleg Drokin --- diff --git a/lustre/ptlrpc/nodemap_range.c b/lustre/ptlrpc/nodemap_range.c index c351f86..3d6ad28 100644 --- a/lustre/ptlrpc/nodemap_range.c +++ b/lustre/ptlrpc/nodemap_range.c @@ -93,7 +93,7 @@ struct lu_nid_range *range_create(struct nodemap_config *config, char *c; int rc; - if (netmask > 999) { + if (netmask > 128) { /* If the netmask is somehow more than three characters * then the logic below could truncate it which could * result in creating a valid netmask value from bad @@ -110,6 +110,11 @@ struct lu_nid_range *range_create(struct nodemap_config *config, libcfs_nidstr(start_nid)); c = strchr(nidstr, '@'); + if (!c) { + CERROR("Invalid nid %s for netmask\n", + libcfs_nidstr(start_nid)); + return NULL; + } /* net = @ */ strscpy(net, c, sizeof(net));