@@ -27,7 +27,10 @@ struct Property {
*/
const char *qdev_prop_name;
const PropertyInfo *info;
+ /** @offset: offset of field in object instance struct */
ptrdiff_t offset;
+ /** @size: size of field in object instance struct */
+ size_t size;
uint8_t bitnr;
/**
* @set_default: true if the default value should be set from @defval,
@@ -28,6 +28,7 @@ extern const PropertyInfo prop_info_link;
.info = &(_prop), \
.offset = offsetof(_state, _field) \
+ type_check(_type, typeof_field(_state, _field)), \
+ .size = sizeof(typeof_field(_state, _field)), \
__VA_ARGS__ \
}
@@ -485,6 +485,7 @@ static void set_prop_arraylen(Object *obj, Visitor *v, const char *name,
* being inside the device struct.
*/
arrayprop->offset = eltptr - (void *)obj;
+ arrayprop->size = prop->arrayfieldsize;
assert(object_field_prop_ptr(obj, arrayprop) == eltptr);
object_property_add_field(obj, propname, arrayprop, op->allow_set);
}
This will let the code that reads/writes the field ensure it will never go out of bounds. Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: "Daniel P. Berrangé" <berrange@redhat.com> Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: qemu-devel@nongnu.org --- include/qom/field-property.h | 3 +++ include/qom/property-types.h | 1 + qom/property-types.c | 1 + 3 files changed, 5 insertions(+)