Whamcloud - gitweb
LU-18571 nodemap: fix coverity issues in range_create() 88/57488/3
authorSebastien Buisson <sbuisson@ddn.com>
Mon, 16 Dec 2024 20:04:56 +0000 (21:04 +0100)
committerOleg Drokin <green@whamcloud.com>
Thu, 2 Jan 2025 20:53:22 +0000 (20:53 +0000)
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 <sbuisson@ddn.com>
Change-Id: I1a6f85f2c9a3591ddd82ed634e9a87902b2b7d0a
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/57488
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/ptlrpc/nodemap_range.c

index c351f86..3d6ad28 100644 (file)
@@ -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 = @<net> */
                strscpy(net, c, sizeof(net));