hw/core/qdev-clock: Fix potential null pointer dereference
PATCH v2 1/1 hw/core/qdev-clock: Fix potential null pointer dereference
qdev_get_clocklist() function returns a pointer to the NamedClockList struct. This function is called in qdev_alias_clock() and the returned pointer is immediately dereferenced without a null check.
Passing clock name that doesn't exist to qdev_get_clocklist() is a programming error, and so this change is not fixing a bug, only making the reporting of that programming error a bit more helpful and bringing it in to line with qdev_get_clock_in() and qdev_get_clock_out().
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2342
--- hw/core/qdev-clock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
hw/core/qdev-clock.c +8 -1
@@ -157,7 +157,14 @@ Clock *qdev_alias_clock(DeviceState *dev, const char *name, DeviceState *alias_dev, const char *alias_name) { NamedClockList *ncl = qdev_get_clocklist(dev, name); -Clock *clk = ncl->clock; +Clock *clk; + +if (!ncl) { +error_report ("Can not find clock '%s' for device type '%s'" , + name,object_get_typename (OBJECT (dev))); +abort (); + } + clk = ncl->clock; ncl =qdev_init_clocklist (alias_dev, alias_name, true, ncl->output, clk);
Signature · 1 line
2.42.0
Quoted 10 lines · hemanshu.khilari.foss
qdev_get_clocklist()function returns a pointer to the NamedClockList struct. This function is called inqdev_alias_clock()and the returned pointer is immediately dereferenced without a null check.Passing clock name that doesn't exist to
qdev_get_clocklist()is a programming error, and so this change is not fixing a bug, only making the reporting of that programming error a bit more helpful and bringing it in to line withqdev_get_clock_in()andqdev_get_clock_out().
Quoted 6 lines
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2342Signed-off-by hemanshu.khilari.foss <[email protected]>---
Thanks for this patch -- I've applied it to my target-arm.next tree, so it will get upstream in a week or two.
-- PMM
Quoted 9 lines · hemanshu.khilari.foss
qdev_get_clocklist()function returns a pointer to the NamedClockList struct. This function is called inqdev_alias_clock()and the returned pointer is immediately dereferenced without a null check.Passing clock name that doesn't exist to
qdev_get_clocklist()is a programming error, and so this change is not fixing a bug, only making the reporting of that programming error a bit more helpful and bringing it in to line withqdev_get_clock_in()andqdev_get_clock_out().
Quoted 5 lines
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/2342Signed-off-by hemanshu.khilari.foss <[email protected]>
Quoted 27 lines
--- hw/core/qdev-clock.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)hw/core/qdev-clock.c +8
-1@@ -157,7 +157,14 @@ Clock *qdev_alias_clock(DeviceState *dev, const char *name, DeviceState *alias_dev, const char *alias_name) { NamedClockList *ncl = qdev_get_clocklist(dev, name); -Clock *clk = ncl->clock; +Clock *clk; + +if (!ncl) { +error_report ("Can not find clock '%s' for device type '%s'" , + name,object_get_typename (OBJECT (dev))); +abort (); + } + clk = ncl->clock; ncl =qdev_init_clocklist (alias_dev, alias_name, true, ncl->output, clk);Signature · 1 line
2.42.0