sysbus_mmio_map_name() passes MemoryRegion.name directly to
strcmp() without checking whether the name is NULL.

Commit e27194e087 ("virtio-gpu-virgl: correct parent for blob
memory region") intentionally introduced a MemoryRegion with a
NULL name, so sysbus_mmio_map_name() should not assume names are
always present.

Add a simple NULL check before calling strcmp().

Signed-off-by: Vineet Agarwal <[email protected]>
---
 hw/core/sysbus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index 3e1160ee92..80cfed442e 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -148,7 +148,9 @@ void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr)
 int sysbus_mmio_map_name(SysBusDevice *dev, const char *name, hwaddr addr)
 {
     for (int i = 0; i < dev->num_mmio; i++) {
-        if (!strcmp(dev->mmio[i].memory->name, name)) {
+        const char *mr_name = dev->mmio[i].memory->name;
+
+        if (mr_name && !strcmp(mr_name, name)) {
             sysbus_mmio_map(dev, i, addr);
             return i;
         }
-- 
2.54.0


Reply via email to