metadata: automatically detect CVE via tags
PATCH 1/1 metadata: automatically detect CVE via tags
From: Andrea Cervesato <[email protected]>
Automatically assign a 'cve' group to test metadata when we are tagging it with a CVE number.
--- metadata/metaparse.c | 43 ++++++++++++++++++++++++++++++++++++++----- metadata/tests/cve.c | 12 ++++++++++++ metadata/tests/cve.c.json | 15 +++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-)
metadata/metaparse.c +38 -5
@@ -52,12 +52,14 @@ static char *eat_asterisk_space(char *c) }/* -* Add a group to the groups array, skipping 'kernel' as it's too generic. -* Returns 0 if no group was added, 1 otherwise. +* Add a group to the groups array, skipping path components that are too +* generic ('kernel') or assigned from a more reliable source ('cve', which +* is derived from the CVE tag instead). Returns 0 if no group was added, +* 1 otherwise. */ static int add_group (struct data_node *groups,const char *name) { -if (name &&strcmp (name,"kernel" )) { +if (name &&strcmp (name,"kernel" ) &&strcmp (name,"cve" )) {data_node_array_add (groups,data_node_string (name));return 1 ; }
@@ -971,11 +973,11 @@ static void load_internal_macros(void)* Add groups derived from the source file path. * * Groups are the two nearest parent directories (immediate parent -* first), skipping 'kernel' as it's too generic: +* first), skipping 'kernel' (too generic) and 'cve' (assigned from the +* CVE tag instead, see add_tag_groups()): * * testcases/kernel/syscalls/clone/clone01.c -> clone, syscalls * testcases/kernel/kvm/kvm_pagefault01.c -> kvm -* testcases/cve/cve-2017-16939.c -> cve */ static void add_path_groups (struct data_node *groups,const char *fname) {
@@ -1010,6 +1012,35 @@ static void add_path_groups(struct data_node *groups, const char *fname)free (buf); } +/* +* Add group to specific test tags. +*/ +static void add_tag_groups (struct data_node *groups,struct data_node *res) +{ +struct data_node *tags =data_node_hash_get (res,"tags" ); +unsigned int i; + +if (!tags || tags->type !=DATA_ARRAY ) +return ; + +for (i =0 ; i <data_node_array_len (tags); i++) { +struct data_node *tag = tags->array.array[i]; +struct data_node *name; + +if (tag->type !=DATA_ARRAY || !data_node_array_len (tag)) +continue ; + + name = tag->array.array[0 ]; +if (name->type !=DATA_STRING ) +continue ; + +if (!strcmp (name->string.val,"CVE" )) { +data_node_array_add (groups,data_node_string ("cve" )); +return ; + } + } +} +static struct data_node *parse_file (const char *fname) {int state =0 , found =0 ;
@@ -1064,6 +1095,8 @@ static struct data_node *parse_file(const char *fname)data_node_free (doc); } +add_tag_groups (groups, res); +/* * Always emit groups, even when empty: tests outside testcases/ * and files whose only parent dir is 'kernel' produce no groups.
metadata/tests/cve.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/*\ +* Test for cve group derived from the CVE tag. +*/ + +static struct tst_test test = { + .tags = (const struct tst_tag []) { + {"CVE" ,"2017-16939" }, + {} + } +};
metadata/tests/cve.c.json new file +15 -0
@@ -0,0 +1,15 @@ + "cve": { + "tags": [ + [ + "CVE", + "2017-16939" + ] + ], + "doc": [ + "Test for cve group derived from the CVE tag." + ], + "groups": [ + "cve" + ], + "fname": "cve.c" + }
---
base-commit: b2184c0f2debb976414b294b8527298bdac0a877
change-id: 20260622-metadata_cve-25cf42b4f38d
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 49 lines
/*
- * Add a group to the groups array, skipping 'kernel' as it's too generic.
- * Returns 0 if no group was added, 1 otherwise.
+ * Add a group to the groups array, skipping path components that are too
+ * generic ('kernel') or assigned from a more reliable source ('cve', which
+ * is derived from the CVE tag instead). Returns 0 if no group was added,
+ * 1 otherwise.
*/
static intadd_group(struct data_node *groups, const char *name){metadata/metaparse.c +19
-3-if (name &&strcmp (name,"kernel" )) { +if (name &&strcmp (name,"kernel" ) &&strcmp (name,"cve" )) {data_node_array_add (groups,data_node_string (name));return 1 ; }@@ -971,11 +973,11 @@ static void load_internal_macros(void)* Add groups derived from the source file path. * * Groups are the two nearest parent directories (immediate parent -* first), skipping 'kernel' as it's too generic: +* first), skipping 'kernel' (too generic) and 'cve' (assigned from the +* CVE tag instead, see add_tag_groups()): * * testcases/kernel/syscalls/clone/clone01.c -> clone, syscalls * testcases/kernel/kvm/kvm_pagefault01.c -> kvm -* testcases/cve/cve-2017-16939.c -> cve */ static void add_path_groups (struct data_node *groups,const char *fname) {@@ -1010,6 +1012,35 @@ static void add_path_groups(struct data_node *groups, const char *fname)free (buf); } +/* +* Add group to specific test tags. +*/ +static void add_tag_groups (struct data_node *groups,struct data_node *res) +{ +struct data_node *tags =data_node_hash_get (res,"tags" ); +unsigned int i; + +if (!tags || tags->type !=DATA_ARRAY ) +return ; + +for (i =0 ; i <data_node_array_len (tags); i++) { +struct data_node *tag = tags->array.array[i]; +struct data_node *name; + +if (tag->type !=DATA_ARRAY || !data_node_array_len (tag))
metadata/metaparse.c static void add_path_groups(struct data_node *groups, const char *fname) · line 1040
Quoted 10 lines
metadata/metaparse.c +10
-0+continue ; + + name = tag->array.array[0 ]; +if (name->type !=DATA_STRING ) +continue ; + +if (!strcmp (name->string.val,"CVE" )) { +data_node_array_add (groups,data_node_string ("cve" )); +return ; + }
We may as well add group "regression" if there is a linux-git tag present.
Otherwise it looks good.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp