Blob Blame History Raw
From 032ca202f839fe1c49cddfd2b0459f9fecc23c86 Mon Sep 17 00:00:00 2001
From: Uri Lublin <uril@redhat.com>
Date: Wed, 11 Nov 2020 20:03:57 +0200
Subject: [PATCH 18/22] spice_usbutil_parse_usbids: verify at least one vendor
 and product

Fixes the following clang warning:
  src/usbutil.c:148:52: warning: Use of zero-allocated memory
  ...

   product_info[product_count].product_id = id;
                                          ^
   146|               while (isspace(line[0]))
   147|                   line++;
   148|->             product_info[product_count].product_id = id;
   149|               snprintf(product_info[product_count].name,
   150|                        PRODUCT_NAME_LEN, "%s", line);

Signed-off-by: Uri Lublin <uril@redhat.com>
---
 src/usbutil.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/usbutil.c b/src/usbutil.c
index 7d7f38a..f29302b 100644
--- a/src/usbutil.c
+++ b/src/usbutil.c
@@ -113,6 +113,13 @@ static gboolean spice_usbutil_parse_usbids(gchar *path)
         usbids_vendor_count++;
     }
 
+    if (usbids_vendor_info == 0 || product_count == 0) {
+        usbids_vendor_count = -1;
+        g_strfreev(lines);
+        g_free(contents);
+        return FALSE;
+    }
+
     usbids_vendor_info = g_new(usb_vendor_info, usbids_vendor_count);
     product_info = g_new(usb_product_info, product_count);
 
-- 
2.28.0