Re: [LTP] [PATCH v4 9/9] [RFC] metaparse: Check {min, max}_kver validity

Cyril Hrubis <[email protected]>
Newsgroups it.linux.lists.ltp
Message-ID <anQ2b1STktuhnLrP@rei>
Hi!
> diff --git a/metadata/Makefile b/metadata/Makefile
> index af194bcc94..9ee2441669 100644
> --- a/metadata/Makefile
> +++ b/metadata/Makefile
> @@ -3,13 +3,15 @@
>  
>  top_srcdir		?= ..
>  
> -include $(top_srcdir)/include/mk/env_pre.mk
> -include $(top_srcdir)/include/mk/functions.mk
> +include $(top_srcdir)/include/mk/testcases.mk
>  
>  MAKE_TARGETS		:= ltp.json
>  HOST_MAKE_TARGETS	:= metaparse metaparse-sh
>  INSTALL_DIR		= metadata
>  
> +metaparse: HOST_CFLAGS		+= -I$(abs_srcdir)/../include -L$(abs_builddir)/../lib
> +metaparse: HOST_LDLIBS		+= -lltp
> +
>  .PHONY: ltp.json
>  
>  ltp.json: metaparse metaparse-sh
> diff --git a/metadata/metaparse.c b/metadata/metaparse.c
> index cb141c3831..07a452a5a1 100644
> --- a/metadata/metaparse.c
> +++ b/metadata/metaparse.c
> @@ -6,6 +6,7 @@
>  
>  #define _GNU_SOURCE
>  
> +#include <assert.h>
>  #include <search.h>
>  #include <stdio.h>
>  #include <string.h>
> @@ -15,6 +16,7 @@
>  #include <errno.h>
>  
>  #include "data_storage.h"
> +#include "tst_kvercmp.h"
>  
>  #define INCLUDE_PATH_MAX 5
>  #define GROUPS_TAG "@groups"
> @@ -1372,6 +1374,37 @@ int main(int argc, char *argv[])
>  		}
>  	}
>  
> +	/* Check max_kver >= min_kver */
> +	struct data_node *max_kver = data_node_hash_get(res, "max_kver");
> +	struct data_node *min_kver = data_node_hash_get(res, "min_kver");
> +	int a1, a2, a3, b1, b2, b3;
> +
> +	if (min_kver) {
> +		assert(min_kver->type == DATA_STRING);
> +		if (tst_parse_kver(min_kver->string.val, &b1, &b2, &b3)) {
> +			fprintf(stderr, "%s: wrong min_kver: '%s'\n",
> +				argv[optind], min_kver->string.val);
> +			return 1;
> +		}
> +	}
> +
> +	if (max_kver) {
> +		assert(max_kver->type == DATA_STRING);
> +		if (tst_parse_kver(max_kver->string.val, &a1, &a2, &a3)) {
> +			fprintf(stderr, "%s: wrong max_kver: '%s'\n",
> +					argv[optind], max_kver->string.val);
> +			return 1;
> +		}
> +	}
> +
> +	if (min_kver && max_kver) {
> +		if (tst_kver_cmp(a1, a2, a3, b1, b2, b3) < 0) {
> +			fprintf(stderr, "%s: min_kver (%s) > max_kver (%s)\n",
> +					argv[optind], min_kver->string.val, max_kver->string.val);
> +			return 1;
> +		}
> +	}
> +

Andrea is working on metadata linter, that does much more than this,
e.g. checks that CVE record is valid.

This looks like a check that could be added more easily there.


-- 
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.