Whamcloud - gitweb
LU-17000 lnet: remove redundant errno check in liblnetconfig.c 46/51846/3
authorJake McManus <jacobpmcmanus@gmail.com>
Thu, 10 Aug 2023 03:12:03 +0000 (23:12 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 31 Aug 2023 06:34:13 +0000 (06:34 +0000)
Variable root is assigned NULL at the beginning of
lustre_lnet_show_stats(). If l_ioctl() fails, its return value
stored in rc will take the True path in the following conditional.
This conditional currently contains a redundant check for errno,
despite the fact that rc would = -errno in this case. If errno had
changed between the l_ioctl() call and this subsequent read, errno
could be 0, which would, from the out: label, lead to a NULL
root being used as a parameter in cYAML_insert_sibling() and
dereferencing the NULL root pointer.

Replaced l_errno's use as a parameter in strerror with -rc, and
removed decleration and other references to l_errno.

Addresses-Coverity-ID: 397850 ("Explicit null dereferenced")

Signed-off-by: Jake McManus <jacobpmcmanus@gmail.com>
Change-Id: I78f080837b60c8216c52bda8562d4c0f9f45a132
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51846
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/utils/lnetconfig/liblnetconfig.c

index 36bb891..7ed9c05 100644 (file)
@@ -4263,7 +4263,6 @@ int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
        struct lnet_ioctl_lnet_stats data;
        struct lnet_counters *cntrs;
        int rc;
-       int l_errno;
        char err_str[LNET_MAX_STR_LEN] = "\"out of memory\"";
        struct cYAML *root = NULL, *stats = NULL;
 
@@ -4271,12 +4270,10 @@ int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
 
        rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_LNET_STATS, &data);
        if (rc) {
-               l_errno = errno;
                snprintf(err_str,
                         sizeof(err_str),
                         "\"cannot get lnet statistics: %s\"",
-                        strerror(l_errno));
-               rc = -l_errno;
+                        strerror(-rc));
                goto out;
        }