[PATCH] pciutils: Fix sysfs_get_string to handle invalid read

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ameya Palande <2ameya@xxxxxxxxx>
---
 lib/sysfs.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/sysfs.c b/lib/sysfs.c
index 9f348bb..8f0cabe 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -105,9 +105,17 @@ sysfs_get_string(struct pci_dev *d, char *object, char *buf, int mandatory)
   n = read(fd, buf, OBJBUFSIZE);
   close(fd);
   if (n < 0)
-    a->error("Error reading %s: %s", namebuf, strerror(errno));
+    {
+      if (mandatory)
+        a->error("Error reading %s: %s", namebuf, strerror(errno));
+      return 0;
+    }
   if (n >= OBJBUFSIZE)
-    a->error("Value in %s too long", namebuf);
+    {
+      if (mandatory)
+        a->error("Value in %s too long", namebuf);
+      return 0;
+    }
   buf[n] = 0;
   return 1;
 }
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux