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>
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;
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;
}