Skip to contentSkip to conversation

qdev: fix NULL deference

PATCH Applied Mark Langsdorf 3 participants 4 messages Mar 13, 2012 – Mar 14, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 qdev: fix NULL deference

From: Joshua Housh <[email protected]>

Make sure a BusInfo exists before trying to dereference it.

---
 hw/qdev.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
hw/qdev.c +6 -3
index ee21d90..6c3d02f 100644
@@ -86,9 +86,12 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
     dev->parent_bus = bus;
     QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
 
-    for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) {
-        qdev_property_add_legacy(dev, prop, NULL);
-        qdev_property_add_static(dev, prop, NULL);
+    BusInfo *info = qdev_get_bus_info(dev);
+    if (info) {
+        for (prop = info->props; prop && prop->name; prop++) {
+            qdev_property_add_legacy(dev, prop, NULL);
+            qdev_property_add_static(dev, prop, NULL);
+        }
     }
     qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
 }
Signature · 1 line
1.7.5.4
#1 lore raw

Am 13.03.2012 19:32, schrieb Mark Langsdorf:

Quoted 3 lines

From: Joshua Housh <[email protected]>

Make sure a BusInfo exists before trying to dereference it.

What's the use case that breaks?

Andreas

Quoted 27 lines
---
 hw/qdev.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
hw/qdev.c +6 -3
index ee21d90..6c3d02f 100644
@@ -86,9 +86,12 @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
     dev->parent_bus = bus;
     QTAILQ_INSERT_HEAD(&bus->children, dev, sibling);
 
-    for (prop = qdev_get_bus_info(dev)->props; prop && prop->name; prop++) {
-        qdev_property_add_legacy(dev, prop, NULL);
-        qdev_property_add_static(dev, prop, NULL);
+    BusInfo *info = qdev_get_bus_info(dev);
+    if (info) {
+        for (prop = info->props; prop && prop->name; prop++) {
+            qdev_property_add_legacy(dev, prop, NULL);
+            qdev_property_add_static(dev, prop, NULL);
+        }
     }
     qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
 }
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 6 lines · Andreas Färber

Am 13.03.2012 19:32, schrieb Mark Langsdorf:

Quoted 3 lines

From: Joshua Housh <[email protected]>

Make sure a BusInfo exists before trying to dereference it.

What's the use case that breaks?

Valid question.

Every qdev has / used to have a parent bus, and every bus info. If that's not true anymore, it would be nice to have the commit message point to the commit that broke it.

#3 lore raw

Am 14.03.2012 08:59, schrieb Markus Armbruster:

Quoted 7 lines
Quoted 5 lines · Andreas Färber

Am 13.03.2012 19:32, schrieb Mark Langsdorf:

Quoted 3 lines

From: Joshua Housh <[email protected]>

Make sure a BusInfo exists before trying to dereference it.

Quoted 7 lines
Quoted 1 line

What's the use case that breaks?

Valid question.

Every qdev has / used to have a parent bus, and every bus info. If that's not true anymore, it would be nice to have the commit message point to the commit that broke it.

My guess would be a direct usage of QOM TYPE_DEVICE, something I've tried to avoid in the CPU series so far... there's likely more things that need changing then.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg