in generic case errp may be NULL and if an Error gets raised in visitor but not set to *errp for the lack of pointer, value might be uninitialized: object_property_parse(obj, "invalid value", "foo", NULL); and accessed futher in property setter leading to incorrect property value of object instance. So we cannot rely on error_is_set(errp) but must use a local variable to detect error condition and return earlier.
Signed-off-by: Igor Mammedov <imamm...@redhat.com> --- target-i386/cpu.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 2220eae..7064818 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -1110,10 +1110,12 @@ static void x86_cpuid_version_set_family(Object *obj, Visitor *v, void *opaque, CPUX86State *env = &cpu->env; const int64_t min = 0; const int64_t max = 0xff + 0xf; + Error *err = NULL; int64_t value; - visit_type_int(v, &value, name, errp); - if (error_is_set(errp)) { + visit_type_int(v, &value, name, &err); + if (err) { + error_propagate(errp, err); return; } if (value < min || value > max) { @@ -1155,10 +1157,12 @@ static void x86_cpuid_version_set_model(Object *obj, Visitor *v, void *opaque, CPUX86State *env = &cpu->env; const int64_t min = 0; const int64_t max = 0xff; + Error *err = NULL; int64_t value; - visit_type_int(v, &value, name, errp); - if (error_is_set(errp)) { + visit_type_int(v, &value, name, &err); + if (err) { + error_propagate(errp, err); return; } if (value < min || value > max) { @@ -1197,10 +1201,12 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, CPUX86State *env = &cpu->env; const int64_t min = 0; const int64_t max = 0xf; + Error *err = NULL; int64_t value; - visit_type_int(v, &value, name, errp); - if (error_is_set(errp)) { + visit_type_int(v, &value, name, &err); + if (err) { + error_propagate(errp, err); return; } if (value < min || value > max) { @@ -1337,10 +1343,12 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor *v, void *opaque, X86CPU *cpu = X86_CPU(obj); const int64_t min = 0; const int64_t max = INT64_MAX; + Error *err = NULL; int64_t value; - visit_type_int(v, &value, name, errp); - if (error_is_set(errp)) { + visit_type_int(v, &value, name, &err); + if (err) { + error_propagate(errp, err); return; } if (value < min || value > max) { -- 1.8.3.1