Blame SOURCES/0025-linux.c-fix-a-pile-of-sscanf-NULL-.-possibilities.patch

ac385c
From d8cef3fe75ef8ca3e2622230c81caba06c3476bd Mon Sep 17 00:00:00 2001
ac385c
From: Peter Jones <pjones@redhat.com>
ac385c
Date: Tue, 9 May 2017 16:33:27 -0400
ac385c
Subject: [PATCH 25/26] linux.c: fix a pile of sscanf(NULL, ...) possibilities.
ac385c
ac385c
Covscan apparently can't figure out that rc!=error == buf!=NULL.
ac385c
ac385c
None of these should ever actually happen, because we're checking for
ac385c
the error cases from the functions that should fill them in, but hey,
ac385c
belt and suspenders.
ac385c
ac385c
Signed-off-by: Peter Jones <pjones@redhat.com>
ac385c
---
ac385c
 src/linux.c | 12 ++++++------
ac385c
 1 file changed, 6 insertions(+), 6 deletions(-)
ac385c
ac385c
diff --git a/src/linux.c b/src/linux.c
ac385c
index 85b4ee3..f419ad4 100644
ac385c
--- a/src/linux.c
ac385c
+++ b/src/linux.c
ac385c
@@ -297,7 +297,7 @@ sysfs_sata_get_port_info(uint32_t print_id, struct disk_info *info)
ac385c
 
ac385c
 	rc = read_sysfs_file(&buf, "/sys/class/ata_port/ata%d/port_no",
ac385c
 			     print_id);
ac385c
-	if (rc <= 0)
ac385c
+	if (rc <= 0 || buf == NULL)
ac385c
 		return -1;
ac385c
 
ac385c
 	rc = sscanf((char *)buf, "%d", &info->sata_info.ata_port);
ac385c
@@ -361,12 +361,12 @@ sysfs_parse_nvme(uint8_t *buf, ssize_t size, ssize_t *off,
ac385c
 	rc = read_sysfs_file(&filebuf,
ac385c
 			     "/sys/class/block/nvme%dn%d/eui",
ac385c
 			     ctrl_id, ns_id);
ac385c
-	if (rc < 0 && errno == ENOENT) {
ac385c
+	if ((rc < 0 && errno == ENOENT) || filebuf == NULL) {
ac385c
 		rc = read_sysfs_file(&filebuf,
ac385c
 			     "/sys/class/block/nvme%dn%d/device/eui",
ac385c
 			     ctrl_id, ns_id);
ac385c
 	}
ac385c
-	if (rc >= 0) {
ac385c
+	if (rc >= 0 && filebuf != NULL) {
ac385c
 		uint8_t eui[8];
ac385c
 		if (rc < 23) {
ac385c
 			errno = EINVAL;
ac385c
@@ -606,7 +606,7 @@ sysfs_parse_sas(uint8_t *buf, ssize_t size, ssize_t *off,
ac385c
 	rc = read_sysfs_file(&filebuf,
ac385c
 			     "/sys/class/block/%s/device/sas_address",
ac385c
 			     disk_name);
ac385c
-	if (rc < 0)
ac385c
+	if (rc < 0 || filebuf == NULL)
ac385c
 		return -1;
ac385c
 
ac385c
 	rc = sscanf((char *)filebuf, "%"PRIx64, &sas_address);
ac385c
@@ -656,7 +656,7 @@ make_pci_path(uint8_t *buf, ssize_t size, char *pathstr, ssize_t *pathoff)
ac385c
 	rc = read_sysfs_file(&fbuf,
ac385c
 			     "/sys/devices/pci%04x:%02x/firmware_node/hid",
ac385c
 			     root_domain, root_bus);
ac385c
-	if (rc < 0)
ac385c
+	if (rc < 0 || fbuf == NULL)
ac385c
 		return -1;
ac385c
 
ac385c
 	uint16_t tmp16 = 0;
ac385c
@@ -679,7 +679,7 @@ make_pci_path(uint8_t *buf, ssize_t size, char *pathstr, ssize_t *pathoff)
ac385c
 	rc = read_sysfs_file(&fbuf,
ac385c
 			     "/sys/devices/pci%4x:%02x/firmware_node/uid",
ac385c
 			     root_domain, root_bus);
ac385c
-	if (rc <= 0 && errno != ENOENT)
ac385c
+	if ((rc <= 0 && errno != ENOENT) || fbuf == NULL)
ac385c
 		return -1;
ac385c
 	if (rc > 0) {
ac385c
 		rc = sscanf((char *)fbuf, "%"PRIu64"\n", &acpi_uid_int);
ac385c
-- 
ac385c
2.12.2
ac385c