sysbus: Guard against NULL SysBusDevice::init fn
PATCH 1/1 sysbus: Guard against NULL SysBusDevice::init fn
In certain cases a device model can init with neither a Device::realize or SysBusDevice::init (i.e. when its possible to do everything in Object::init). In this case, the device model should be able to leave both SysBusDevice::init and Device::realize as NULL. However what happens in this case in SysBus's default Device::realize function will try and call SysBusDevice::init without checking if it actually exists. A segfault ensues.
Fix by guarding the call to SysBusDevice::init against a NULL pointer. If no pointer is defined return 0 without action.
--- hw/sysbus.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/sysbus.c +1 -1
@@ -118,7 +118,7 @@ static int sysbus_device_init(DeviceState *dev)SysBusDevice *sd =SYS_BUS_DEVICE (dev);SysBusDeviceClass *sbc =SYS_BUS_DEVICE_GET_CLASS (sd); -return sbc->init (sd); +return sbc->init ? sbc->init (sd) :0 ; } DeviceState *sysbus_create_varargs(const char *name,
Signature · 1 line
1.7.0.4
Am 03.03.2013 06:30, schrieb Peter Crosthwaite:
Quoted 11 lines
In certain cases a device model can init with neither a
Device::realizeorSysBusDevice::init(i.e. when its possible to do everything inObject::init). In this case, the device model should be able to leave bothSysBusDevice::initandDevice::realizeas NULL. However what happens in this case in SysBus's defaultDevice::realizefunction will try and callSysBusDevice::initwithout checking if it actually exists. A segfault ensues.Fix by guarding the call to
SysBusDevice::initagainst a NULL pointer. If no pointer is defined return 0 without action.Signed-off-by Peter Crosthwaite <[email protected]>
While the patch is correct, I believe PMM already posted one using an extra if two weeks ago as part of some series...
Andreas
Quoted 18 lines
--- hw/sysbus.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)hw/sysbus.c +1
-1@@ -118,7 +118,7 @@ static int sysbus_device_init(DeviceState *dev)SysBusDevice *sd =SYS_BUS_DEVICE (dev);SysBusDeviceClass *sbc =SYS_BUS_DEVICE_GET_CLASS (sd); -return sbc->init (sd); +return sbc->init ? sbc->init (sd) :0 ; } DeviceState *sysbus_create_varargs(const char *name,
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
Quoted 8 lines · Andreas Färber
Am 03.03.2013 06:30, schrieb Peter Crosthwaite:
Quoted 4 lines
Fix by guarding the call to
SysBusDevice::initagainst a NULL pointer. If no pointer is defined return 0 without action.Signed-off-by Peter Crosthwaite <[email protected]>While the patch is correct, I believe PMM already posted one using an extra if two weeks ago as part of some series...
Yep, http://patchwork.ozlabs.org/patch/222985/
-- PMM