* [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {}
@ 2022-03-14 13:06 Richard Palethorpe via ltp
2022-03-14 13:06 ` [LTP] [PATCH 2/2] LTP-005: Switch opts terminator to {} Richard Palethorpe via ltp
2022-03-15 9:14 ` [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} Petr Vorel
0 siblings, 2 replies; 5+ messages in thread
From: Richard Palethorpe via ltp @ 2022-03-14 13:06 UTC (permalink / raw)
To: ltp; +Cc: Richard Palethorpe
Check for null termination on tst_test.save_restore and all the other
struct arrays in tst_test. They are all null terminated.
Also prevents a segfault when scalar NULL is used as the final entry
and print a helpful error message instead.
Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
Suggested-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
tools/sparse/sparse-ltp.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/tools/sparse/sparse-ltp.c b/tools/sparse/sparse-ltp.c
index 608025800..d649ee7b7 100644
--- a/tools/sparse/sparse-ltp.c
+++ b/tools/sparse/sparse-ltp.c
@@ -178,27 +178,31 @@ static bool is_terminated_with_null_struct(const struct symbol *const sym)
if (item_init->type == EXPR_POS)
item_init = item_init->init_expr;
+ if (item_init->type != EXPR_INITIALIZER)
+ return false;
+
return ptr_list_empty((struct ptr_list *)item_init->expr_list);
}
-/* Check for (one instance of) LTP-005
+/* LTP-005: Check array sentinel value
*
- * The tags array is only accessed when the test fails. So we perform
- * a static check to ensure it ends with {}
+ * This is most important for the tags array. It is only accessed when
+ * the test fails. So we perform a static check to ensure it ends with
+ * {}.
*/
-static void check_tag_initializer(const struct symbol *const sym)
+static void check_struct_array_initializer(const struct symbol *const sym)
{
if (is_terminated_with_null_struct(sym))
return;
warning(sym->pos,
- "LTP-005: test.tags array doesn't appear to be null-terminated; did you forget to add '{}' as the final entry?");
+ "LTP-005: Struct array doesn't appear to be null-terminated; did you forget to add '{}' as the final entry?");
}
/* Find struct tst_test test = { ... } and perform tests on its initializer */
static void check_test_struct(const struct symbol *const sym)
{
- static struct ident *tst_test, *tst_test_test, *tst_tag;
+ static struct ident *tst_test, *tst_test_test;
struct ident *ctype_name = NULL;
struct expression *init = sym->initializer;
struct expression *entry;
@@ -214,7 +218,6 @@ static void check_test_struct(const struct symbol *const sym)
if (!tst_test_test) {
tst_test = built_in_ident("tst_test");
tst_test_test = built_in_ident("test");
- tst_tag = built_in_ident("tst_tag");
}
if (sym->ident != tst_test_test)
@@ -227,11 +230,19 @@ static void check_test_struct(const struct symbol *const sym)
if (entry->init_expr->type != EXPR_SYMBOL)
continue;
+ switch (entry->ctype->ctype.base_type->type) {
+ case SYM_PTR:
+ case SYM_ARRAY:
+ break;
+ default:
+ return;
+ }
+
const struct symbol *entry_init = entry->init_expr->symbol;
const struct symbol *entry_ctype = unwrap_base_type(entry_init);
- if (entry_ctype->ident == tst_tag)
- check_tag_initializer(entry_init);
+ if (entry_ctype->type == SYM_STRUCT)
+ check_struct_array_initializer(entry_init);
} END_FOR_EACH_PTR(entry);
}
--
2.35.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread* [LTP] [PATCH 2/2] LTP-005: Switch opts terminator to {} 2022-03-14 13:06 [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} Richard Palethorpe via ltp @ 2022-03-14 13:06 ` Richard Palethorpe via ltp 2022-03-15 9:15 ` Petr Vorel 2022-03-15 9:14 ` [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} Petr Vorel 1 sibling, 1 reply; 5+ messages in thread From: Richard Palethorpe via ltp @ 2022-03-14 13:06 UTC (permalink / raw) To: ltp; +Cc: Richard Palethorpe Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com> --- .../kernel/security/integrity/ima/src/ima_boot_aggregate.c | 2 +- testcases/network/nfs/nfs_stress/nfs05_make_tree.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c b/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c index 05c20e5ae..62468e0d1 100644 --- a/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c +++ b/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c @@ -125,7 +125,7 @@ static void do_test(void) static struct tst_option options[] = { {"d", &debug, "Enable debug"}, {"f:", &file, "binary_bios_measurement file (required)\n"}, - {NULL, NULL, NULL} + {} }; static struct tst_test test = { diff --git a/testcases/network/nfs/nfs_stress/nfs05_make_tree.c b/testcases/network/nfs/nfs_stress/nfs05_make_tree.c index add55e156..fdc13bd5d 100644 --- a/testcases/network/nfs/nfs_stress/nfs05_make_tree.c +++ b/testcases/network/nfs/nfs_stress/nfs05_make_tree.c @@ -63,7 +63,7 @@ static struct tst_option opts[] = { {"t:", &t_arg, "Number of threads to generate, default: 8"}, {"d:", &d_arg, "Number of subdirs to generate, default: 100"}, {"f:", &f_arg, "Number of c files in each dir, default: 100"}, - {NULL, NULL, NULL} + {} }; static void run_targets(const char *dirname, char *cfile, pid_t tid) -- 2.35.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH 2/2] LTP-005: Switch opts terminator to {} 2022-03-14 13:06 ` [LTP] [PATCH 2/2] LTP-005: Switch opts terminator to {} Richard Palethorpe via ltp @ 2022-03-15 9:15 ` Petr Vorel 0 siblings, 0 replies; 5+ messages in thread From: Petr Vorel @ 2022-03-15 9:15 UTC (permalink / raw) To: Richard Palethorpe; +Cc: ltp Hi Richie, obviously correct. Thanks! Reviewed-by: Petr Vorel <pvorel@suse.cz> Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} 2022-03-14 13:06 [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} Richard Palethorpe via ltp 2022-03-14 13:06 ` [LTP] [PATCH 2/2] LTP-005: Switch opts terminator to {} Richard Palethorpe via ltp @ 2022-03-15 9:14 ` Petr Vorel 2022-03-15 12:53 ` Richard Palethorpe 1 sibling, 1 reply; 5+ messages in thread From: Petr Vorel @ 2022-03-15 9:14 UTC (permalink / raw) To: Richard Palethorpe; +Cc: ltp Hi Richie, > Check for null termination on tst_test.save_restore and all the other > struct arrays in tst_test. They are all null terminated. > Also prevents a segfault when scalar NULL is used as the final entry > and print a helpful error message instead. thanks for this! LGTM. Reviewed-by: Petr Vorel <pvorel@suse.cz> Kind regards, Petr -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} 2022-03-15 9:14 ` [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} Petr Vorel @ 2022-03-15 12:53 ` Richard Palethorpe 0 siblings, 0 replies; 5+ messages in thread From: Richard Palethorpe @ 2022-03-15 12:53 UTC (permalink / raw) To: Petr Vorel; +Cc: ltp Hello Petr, Petr Vorel <pvorel@suse.cz> writes: > Hi Richie, > >> Check for null termination on tst_test.save_restore and all the other >> struct arrays in tst_test. They are all null terminated. > >> Also prevents a segfault when scalar NULL is used as the final entry >> and print a helpful error message instead. > > thanks for this! LGTM. > Reviewed-by: Petr Vorel <pvorel@suse.cz> > > Kind regards, > Petr Thanks merged! -- Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-03-15 12:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-14 13:06 [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} Richard Palethorpe via ltp
2022-03-14 13:06 ` [LTP] [PATCH 2/2] LTP-005: Switch opts terminator to {} Richard Palethorpe via ltp
2022-03-15 9:15 ` Petr Vorel
2022-03-15 9:14 ` [LTP] [PATCH 1/2] tools/sparse-ltp: Check all struct arrays in tst_test for ending {} Petr Vorel
2022-03-15 12:53 ` Richard Palethorpe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox