From: Thomas Huth <th...@redhat.com>

When compiling QEMU with --enable-ubsan there is a undefined behavior
warning when running "make check":

 .../qga/commands-linux.c:452:15: runtime error: applying non-zero offset 5 to 
null pointer
 #0 0x55ea7b89450c in build_guest_fsinfo_for_pci_dev 
..../qga/commands-linux.c:452:15

Add a check to avoid incrementing the NULL pointer here.

Signed-off-by: Thomas Huth <th...@redhat.com>
---
 qga/commands-linux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/qga/commands-linux.c b/qga/commands-linux.c
index 9e8a934b9a6..caf7c3ca22b 100644
--- a/qga/commands-linux.c
+++ b/qga/commands-linux.c
@@ -449,7 +449,9 @@ static bool build_guest_fsinfo_for_pci_dev(char const 
*syspath,
         has_ata = true;
     } else {
         p = strstr(syspath, "/host");
-        q = p + 5;
+        if (p) {
+            q = p + 5;
+        }
     }
     if (p && sscanf(q, "%u", &host) == 1) {
         has_host = true;
-- 
2.50.1


Reply via email to