qom: fix qdict visit in user_creatable_add_type
PATCH 1/1 qom: fix qdict visit in user_creatable_add_type
This fixes a Qemu crash that introduced by commit ad73970 ("qom: Wrap prop visit in visit_start_struct").
Not all of the callers of user_creatable_add_type always pass qdict, so we should check qdict against NULL, but not raise an assertion.
The problem can be easily triggered by adding an iothread with:
$ virsh iothreadadd <domain> <threadid> In which the <threadid> is newly defined. The result of the command will return an error and cause the running guest crash.
--- qom/object_interfaces.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
qom/object_interfaces.c +16 -15
@@ -112,24 +112,25 @@ Object *user_creatable_add_type(const char *type, const char *id,return NULL ; } -assert (qdict); obj =object_new (type); -visit_start_struct (v,NULL ,NULL ,0 , &local_err); -if (local_err) { - goto out; - } -for (e =qdict_first (qdict); e; e =qdict_next (qdict, e)) { -object_property_set (obj, v, e->key, &local_err); +if (qdict) { +visit_start_struct (v,NULL ,NULL ,0 , &local_err);if (local_err) { -break ; + goto out; + } +for (e =qdict_first (qdict); e; e =qdict_next (qdict, e)) { +object_property_set (obj, v, e->key, &local_err); +if (local_err) { +break ; + } + } +if (!local_err) { +visit_check_struct (v, &local_err); + } +visit_end_struct (v,NULL ); +if (local_err) { + goto out; } - } -if (!local_err) { -visit_check_struct (v, &local_err); - } -visit_end_struct (v,NULL ); -if (local_err) { - goto out; } object_property_add_child(object_get_objects_root(),
Signature · 1 line
2.8.4
Quoted 7 lines · Xiao Long Jiang
This fixes a Qemu crash that introduced by commit ad73970 ("qom: Wrap prop visit in
visit_start_struct").Not all of the callers of
user_creatable_add_typealways pass qdict, so we should check qdict against NULL, but not raise an assertion.The problem can be easily triggered by adding an iothread with:
Quoted 8 lines
$ virsh iothreadadd <domain> <threadid> In which the <threadid> is newly defined. The result of the command will return an error and cause the running guest crash.Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by Xiao Long Jiang <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>
Marc-André already posted a simpler fix:
Subject: [PATCH] qmp: fix object-add assert() without props
Message-Id: <[email protected]>
Would you be willing to test it? Review would of course also be appreciated.
Thanks!
Hi Markus,
Quoted 17 lines · Markus Armbruster
Quoted 7 lines · Xiao Long Jiang
This fixes a Qemu crash that introduced by commit ad73970 ("qom: Wrap prop visit in
visit_start_struct").Not all of the callers of
user_creatable_add_typealways pass qdict, so we should check qdict against NULL, but not raise an assertion.The problem can be easily triggered by adding an iothread with:
Quoted 8 lines
$ virsh iothreadadd <domain> <threadid> In which the <threadid> is newly defined. The result of the command will return an error and cause the running guest crash.Cc Eric Blake <[email protected]>Cc Markus Armbruster <[email protected]>Signed-off-by Xiao Long Jiang <[email protected]>Reviewed-by Dong Jia Shi <[email protected]>
Quoted 8 lines
Marc-André already posted a simpler fix:
Subject: [PATCH] qmp: fix object-addassert()without props
Message-Id: <[email protected]>Would you be willing to test it? Review would of course also be appreciated.
Thanks!
Have tested that patch. It works fine on arch s390 system.