qom: Fix misuse of Error API
v2 cover qom: Fix misuse of Error API
v1 was posted for possible inclusion into 2.4, but the maintainer didn't bite ;-)
v2:
* Commit messages updated.
Markus Armbruster (2):
qom: Do not reuse errp after a possible error
qom: Fix invalid error check in property_get_str()
qom/object.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-)
Signature · 1 line
2.4.3
PATCH v2 1/2 qom: Do not reuse errp after a possible error
The argument for an Error **errp parameter must point to a null pointer. If it doesn't, and an error happens, error_set() fails its assertion.
Instead of
foo(foos, errp);
bar(bars, errp);you need to do something like
Error *err = NULL;
foo(foos, &err);
if (err) {
error_propagate(errp, err);
goto out;
}
bar(bars, errp);out:
Screwed up in commit 0e55884 (v1.3.0): property_get_bool().
Screwed up in commit 1f21772 (v2.1.0): object_property_get_enum() and object_property_get_uint16List().
Screwed up in commit a8e3fbe (v2.4.0): property_get_enum(), property_set_enum().
Found by inspection, no actual crashes observed.
Fix them up.
--- qom/object.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-)
qom/object.c +35 -6
@@ -1079,6 +1079,7 @@ typedef struct EnumProperty {int object_property_get_enum (Object *obj,const char *name,const char *typename,Error **errp) { +Error *err =NULL ;StringOutputVisitor *sov;StringInputVisitor *siv;char *str;
@@ -1100,7 +1101,12 @@ int object_property_get_enum(Object *obj, const char *name, enumprop = prop->opaque; sov =string_output_visitor_new (false); -object_property_get (obj,string_output_get_visitor (sov), name, errp); +object_property_get (obj,string_output_get_visitor (sov), name, &err); +if (err) { +error_propagate (errp, err); +string_output_visitor_cleanup (sov); +return 0 ; + } str =string_output_get_string (sov); siv =string_input_visitor_new (str);string_output_visitor_cleanup (sov);
@@ -1116,21 +1122,27 @@ int object_property_get_enum(Object *obj, const char *name,void object_property_get_uint16List (Object *obj,const char *name,uint16List **list,Error **errp) { +Error *err =NULL ;StringOutputVisitor *ov;StringInputVisitor *iv;char *str; ov =string_output_visitor_new (false);object_property_get (obj,string_output_get_visitor (ov), - name, errp); + name, &err); +if (err) { +error_propagate (errp, err); + goto out; + } str =string_output_get_string (ov); iv =string_input_visitor_new (str);visit_type_uint16List (string_input_get_visitor (iv), list,NULL , errp);g_free (str); -string_output_visitor_cleanup (ov);string_input_visitor_cleanup (iv); +out: +string_output_visitor_cleanup (ov); } void object_property_parse(Object *obj, const char *string,
@@ -1644,10 +1656,16 @@ typedef struct BoolPropertystatic void property_get_bool (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) { +Error *err =NULL ;BoolProperty *prop = opaque;bool value; - value = prop->get (obj, errp); + value = prop->get (obj, &err); +if (err) { +error_propagate (errp, err); +return ; + } +visit_type_bool (v, &value, name, errp); }
@@ -1699,20 +1717,31 @@ void object_property_add_bool(Object *obj, const char *name,static void property_get_enum (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) { +Error *err =NULL ;EnumProperty *prop = opaque;int value; - value = prop->get (obj, errp); + value = prop->get (obj, &err); +if (err) { +error_propagate (errp, err); +return ; + } +visit_type_enum (v, &value, prop->strings,NULL , name, errp); }static void property_set_enum (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) { +Error *err =NULL ;EnumProperty *prop = opaque;int value; -visit_type_enum (v, &value, prop->strings,NULL , name, errp); +visit_type_enum (v, &value, prop->strings,NULL , name, &err); +if (err) { +error_propagate (errp, err); +return ; + } prop->set (obj, value, errp); }
Signature · 1 line
2.4.3
PATCH v2 2/2 qom: Fix invalid error check in property_get_str()
In reply to Markus ArmbrusterWhen a function returns a null pointer on error and only on error, you can do
if (!foo(foos, errp)) {
... handle error ...
}instead of the more cumbersome
Error *err = NULL;
if (!foo(foos, &err)) {
error_propagate(errp, err);
... handle error ...
}A StringProperty's getter, however, may return null on success! We then fail to call visit_type_str().
Screwed up in 6a146eb, v1.1.
Fails tests/qom-test in my current, heavily hacked QAPI branch. No reproducer for master known (but I didn't look hard).
--- qom/object.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
qom/object.c +8 -4
@@ -1591,14 +1591,18 @@ typedef struct StringPropertystatic void property_get_str (Object *obj,Visitor *v,void *opaque,const char *name,Error **errp) { +Error *err =NULL ;StringProperty *prop = opaque;char *value; - value = prop->get (obj, errp); -if (value) { -visit_type_str (v, &value, name, errp); -g_free (value); + value = prop->get (obj, &err); +if (err) { +error_propagate (errp, err); +return ; } + +visit_type_str (v, &value, name, errp); +g_free (value); } static void property_set_str(Object *obj, Visitor *v, void *opaque,
Signature · 1 line
2.4.3
Ping?
My "qapi: QMP introspection" series fails "make check" without these fixes.
Quoted 12 lines · Markus Armbruster
v1 was posted for possible inclusion into 2.4, but the maintainer didn't bite ;-)
v2:
* Commit messages updated.Markus Armbruster (2):
qom: Do not reuse errp after a possible error
qom: Fix invalid error check inproperty_get_str()qom/object.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-)
Quoted 16 lines · Markus Armbruster
Ping?
My "qapi: QMP introspection" series fails "make check" without these fixes.
Quoted 9 lines · Markus Armbruster
v1 was posted for possible inclusion into 2.4, but the maintainer didn't bite ;-)
v2:
* Commit messages updated.Markus Armbruster (2):
qom: Do not reuse errp after a possible error
qom: Fix invalid error check inproperty_get_str()
Were you waiting for further review, or for the maintainer to speak up?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 11 lines · Eric Blake
Quoted 10 lines · Markus Armbruster
Ping?
My "qapi: QMP introspection" series fails "make check" without these fixes.
Quoted 3 lines · Markus Armbruster
v1 was posted for possible inclusion into 2.4, but the maintainer didn't bite ;-)
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
v2:
* Commit messages updated.Markus Armbruster (2):
qom: Do not reuse errp after a possible error
qom: Fix invalid error check inproperty_get_str()Were you waiting for further review, or for the maintainer to speak up?
The latter. Andreas spoke up on IRC, and I hope he can get to this small series in the next few days.
Andreas Färber
AppliedAm 03.09.2015 um 18:15 schrieb Markus Armbruster:
Quoted 15 lines
Quoted 14 lines · Eric Blake
Quoted 13 lines · Markus Armbruster
Ping?
My "qapi: QMP introspection" series fails "make check" without these fixes.
Quoted 6 lines · Markus Armbruster
v1 was posted for possible inclusion into 2.4, but the maintainer didn't bite ;-)
v2:
* Commit messages updated.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 3 lines
Markus Armbruster (2):
qom: Do not reuse errp after a possible error
qom: Fix invalid error check inproperty_get_str()Were you waiting for further review, or for the maintainer to speak up?
The latter. Andreas spoke up on IRC, and I hope he can get to this small series in the next few days.
Applied to qom-next, with stylistic changes to keep opaque variables first.
https://github.com/afaerber/qemu-cpu/commits/qom-next
Thanks,
Andreas
Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)