diff mbox series

[2/7] qom: Save size of struct field in Property struct

Message ID 20201104172512.2381656-3-ehabkost@redhat.com
State New
Headers show
Series [1/7] sparc: Fix property/field size mismatch for iu-version | expand

Commit Message

Eduardo Habkost Nov. 4, 2020, 5:25 p.m. UTC
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(+)
diff mbox series

Patch

diff --git a/include/qom/field-property.h b/include/qom/field-property.h
index bc866e1c93..e64a2b3c07 100644
--- a/include/qom/field-property.h
+++ b/include/qom/field-property.h
@@ -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,
diff --git a/include/qom/property-types.h b/include/qom/property-types.h
index 3a36e1fec5..17bf007234 100644
--- a/include/qom/property-types.h
+++ b/include/qom/property-types.h
@@ -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__                                              \
         }
 
diff --git a/qom/property-types.c b/qom/property-types.c
index f566c05ec2..856b5ae76d 100644
--- a/qom/property-types.c
+++ b/qom/property-types.c
@@ -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);
     }