On 05/03/24 19:07, Kees Cook wrote:
The norm should be flexible array structures with __counted_by
annotations, so DEFINE_FLEX() is updated to expect that. Rename
the non-annotated version to DEFINE_RAW_FLEX(), and update the few
existing users. Additionally add self-tests to validate syntax and
size calculations.
Signed-off-by: Kees Cook <keescook@xxxxxxxxxxxx>
---
[..]
+/**
+ * DEFINE_FLEX() - Define an on-stack instance of structure with a trailing
+ * flexible array member.
+ *
+ * @TYPE: structure type name, including "struct" keyword.
+ * @NAME: Name for a variable to define.
+ * @COUNTER: Name of the __counted_by member.
+ * @MEMBER: Name of the array member.
+ * @COUNT: Number of elements in the array; must be compile-time const.
+ *
+ * Define a zeroed, on-stack, instance of @TYPE structure with a trailing
+ * flexible array member.
+ * Use __struct_size(@NAME) to get compile-time size of it afterwards.
+ */
+#define DEFINE_FLEX(TYPE, NAME, COUNTER, MEMBER, COUNT) \
Probably, swapping COUNTER and MEMBER is better?
DEFINE_FLEX(TYPE, NAME, MEMBER, COUNTER, COUNT)
Thanks
--
Gustavo