qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Eduardo Habkost
Subject: [PATCH 2/7] qom: Save size of struct field in Property struct
Date: Wed, 4 Nov 2020 12:25:07 -0500

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 --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);
     }
-- 
2.28.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]