OSDN Git Service

Pacify some coverity nits.
authorPeter Jones <pjones@redhat.com>
Tue, 12 Jun 2018 18:36:20 +0000 (14:36 -0400)
committerPeter Jones <pjones@redhat.com>
Tue, 12 Jun 2018 18:36:20 +0000 (14:36 -0400)
Coverity has trouble tracking data flow sometimes, and believes that
sysfs_readlink() and read_sysfs_file() will sometimes return >= 0 when
the buffer has not been filled out.  This changes the check to also test
for a NULL pointer, hopefully pacifying it.

Signed-off-by: Peter Jones <pjones@redhat.com>
src/linux-pci.c
src/linux.c

index 87878c3..0d2a90a 100644 (file)
@@ -166,7 +166,7 @@ parse_pci(struct device *dev, const char *current)
                 tmp[devpart - current] = '\0';
                 rc = sysfs_readlink(&linkbuf, "class/block/%s/driver", tmp);
                 free(tmp);
-                if (rc < 0) {
+                if (rc < 0 || !linkbuf) {
                         efi_error("Could not find driver for pci device");
                         return -1;
                 }
index c8d1b3a..fe45c60 100644 (file)
@@ -356,7 +356,7 @@ struct device HIDDEN
 
         if (dev->part == -1) {
                 rc = read_sysfs_file(&tmpbuf, "dev/block/%s/partition", dev->link);
-                if (rc < 0) {
+                if (rc < 0 || !tmpbuf) {
                         efi_error("device has no /partition node; not a partition");
                 } else {
                         rc = sscanf((char *)tmpbuf, "%d\n", &dev->part);