mirror of https://gitee.com/openkylin/qemu.git
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 commit0e55884
(v1.3.0): property_get_bool(). Screwed up in commit1f21772
(v2.1.0): object_property_get_enum() and object_property_get_uint16List(). Screwed up in commita8e3fbe
(v2.4.0): property_get_enum(), property_set_enum(). Found by inspection, no actual crashes observed. Fix them up. Cc: Anthony Liguori <anthony@codemonkey.ws> Cc: Hu Tao <hutao@cn.fujitsu.com> Cc: Daniel P. Berrange <berrange@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Daniel P. Berrange <berrange@redhat.com> Cc: qemu-stable@nongnu.org Signed-off-by: Andreas Färber <afaerber@suse.de>
This commit is contained in:
parent
b12a84ce3c
commit
4715d42efe
41
qom/object.c
41
qom/object.c
|
@ -1098,6 +1098,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;
|
||||
|
@ -1119,7 +1120,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);
|
||||
|
@ -1135,21 +1141,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,
|
||||
|
@ -1665,8 +1677,14 @@ static void property_get_bool(Object *obj, Visitor *v, void *opaque,
|
|||
{
|
||||
BoolProperty *prop = opaque;
|
||||
bool value;
|
||||
Error *err = NULL;
|
||||
|
||||
value = prop->get(obj, &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
return;
|
||||
}
|
||||
|
||||
value = prop->get(obj, errp);
|
||||
visit_type_bool(v, &value, name, errp);
|
||||
}
|
||||
|
||||
|
@ -1720,8 +1738,14 @@ static void property_get_enum(Object *obj, Visitor *v, void *opaque,
|
|||
{
|
||||
EnumProperty *prop = opaque;
|
||||
int value;
|
||||
Error *err = NULL;
|
||||
|
||||
value = prop->get(obj, &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
return;
|
||||
}
|
||||
|
||||
value = prop->get(obj, errp);
|
||||
visit_type_enum(v, &value, prop->strings, NULL, name, errp);
|
||||
}
|
||||
|
||||
|
@ -1730,8 +1754,13 @@ static void property_set_enum(Object *obj, Visitor *v, void *opaque,
|
|||
{
|
||||
EnumProperty *prop = opaque;
|
||||
int value;
|
||||
Error *err = NULL;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue