Skip to content

Commit ad9f265

Browse files
committed
stackinit: Add old-style zero-init syntax to struct tests
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>
1 parent a9a5e0b commit ad9f265

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/stackinit_kunit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ static bool stackinit_range_contains(char *haystack_start, size_t haystack_size,
101101

102102
#define INIT_STRUCT_none(var_type) /**/
103103
#define INIT_STRUCT_zero(var_type) = { }
104+
#define INIT_STRUCT_old_zero(var_type) = { 0 }
104105

105106

106107
#define __static_partial { .two = 0, }
@@ -346,6 +347,7 @@ struct test_user {
346347
/* These should be fully initialized all the time! */
347348
DEFINE_SCALAR_TESTS(zero, ALWAYS_PASS);
348349
DEFINE_STRUCT_TESTS(zero, ALWAYS_PASS);
350+
DEFINE_STRUCT_TESTS(old_zero, ALWAYS_PASS);
349351
/* Struct initializers: padding may be left uninitialized. */
350352
DEFINE_STRUCT_INITIALIZER_TESTS(static, STRONG_PASS);
351353
DEFINE_STRUCT_INITIALIZER_TESTS(dynamic, STRONG_PASS);
@@ -440,6 +442,7 @@ static struct kunit_case stackinit_test_cases[] = {
440442
/* These are explicitly initialized and should always pass. */
441443
KUNIT_test_scalars(zero),
442444
KUNIT_test_structs(zero),
445+
KUNIT_test_structs(old_zero),
443446
/* Padding here appears to be accidentally always initialized? */
444447
KUNIT_test_structs(dynamic_partial),
445448
KUNIT_test_structs(assigned_dynamic_partial),

0 commit comments

Comments
 (0)