Blob Blame History Raw
From 972fbddde526de1249894260b7755ec6431ef609 Mon Sep 17 00:00:00 2001
From: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
Date: Mon, 9 Jan 2017 22:07:18 +0100
Subject: [PATCH 42/43] Add forgetten size checks when using loadfile.

This makes sure that lshw won't segfault when dealing
with empty files. This is similar to the following commit:
"osutils: don't segfault on empty files."

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
---
 src/core/dasd.cc | 2 +-
 src/core/pci.cc  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/core/dasd.cc b/src/core/dasd.cc
index 626b8a8..b62a7ee 100644
--- a/src/core/dasd.cc
+++ b/src/core/dasd.cc
@@ -47,7 +47,7 @@ bool scan_dasd(hwNode & n)
       {
         std::string attrib_fname = std::string(SYSFS_PREFIX) + dev_name + "/device/" + *it;
         std::vector<std::string> lines;
-        if (loadfile(attrib_fname, lines))
+        if (loadfile(attrib_fname, lines) && (lines.size() > 0))
         {
           dasd_attribs[*it] = lines[0];
         }
diff --git a/src/core/pci.cc b/src/core/pci.cc
index 1d2b4ee..d1625cf 100644
--- a/src/core/pci.cc
+++ b/src/core/pci.cc
@@ -518,7 +518,7 @@ static bool load_pcidb()
   for (int i = filenames.size() - 1; i >= 0; i--)
   {
     lines.clear();
-    if (loadfile(filenames[i], lines))
+    if (loadfile(filenames[i], lines) && (lines.size() > 0))
       parse_pcidb(lines);
   }
 
-- 
2.10.2