]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
stackinit: Add old-style zero-init syntax to struct tests
authorKees Cook <kees@kernel.org>
Mon, 27 Jan 2025 19:10:26 +0000 (11:10 -0800)
committerKees Cook <kees@kernel.org>
Thu, 30 Jan 2025 16:48:28 +0000 (08:48 -0800)
The deprecated way to do a full zero init of a structure is with "= { 0 }",
but we weren't testing this style. Add it.

Link: https://lore.kernel.org/r/20250127191031.245214-1-kees@kernel.org
Signed-off-by: Kees Cook <kees@kernel.org>
lib/stackinit_kunit.c

index c40818ec9c1801186f007595107f9faf41ca8c5f..7cc9af181e89848a298544352d90b56aa38bc4dc 100644 (file)
@@ -101,6 +101,7 @@ static bool stackinit_range_contains(char *haystack_start, size_t haystack_size,
 
 #define INIT_STRUCT_none(var_type)     /**/
 #define INIT_STRUCT_zero(var_type)     = { }
+#define INIT_STRUCT_old_zero(var_type) = { 0 }
 
 
 #define __static_partial               { .two = 0, }
@@ -346,6 +347,7 @@ struct test_user {
 /* These should be fully initialized all the time! */
 DEFINE_SCALAR_TESTS(zero, ALWAYS_PASS);
 DEFINE_STRUCT_TESTS(zero, ALWAYS_PASS);
+DEFINE_STRUCT_TESTS(old_zero, ALWAYS_PASS);
 /* Struct initializers: padding may be left uninitialized. */
 DEFINE_STRUCT_INITIALIZER_TESTS(static, STRONG_PASS);
 DEFINE_STRUCT_INITIALIZER_TESTS(dynamic, STRONG_PASS);
@@ -440,6 +442,7 @@ static struct kunit_case stackinit_test_cases[] = {
        /* These are explicitly initialized and should always pass. */
        KUNIT_test_scalars(zero),
        KUNIT_test_structs(zero),
+       KUNIT_test_structs(old_zero),
        /* Padding here appears to be accidentally always initialized? */
        KUNIT_test_structs(dynamic_partial),
        KUNIT_test_structs(assigned_dynamic_partial),