[dpdk-dev] [PATCH] app/testpmd: add boundary check in flow commandline

Ananyev, Konstantin konstantin.ananyev at intel.com
Tue Dec 4 10:22:21 CET 2018



> -----Original Message-----
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Wei Zhao
> Sent: Tuesday, December 4, 2018 5:52 AM
> To: dev at dpdk.org
> Cc: stable at dpdk.org; Peng, Yuan <yuan.peng at intel.com>; Zhao1, Wei <wei.zhao1 at intel.com>
> Subject: [dpdk-dev] [PATCH] app/testpmd: add boundary check in flow commandline
> 
> There is need to add boundary for input number from commandline,
> If it beyond the defination, code will return error.
> 
> Signed-off-by: Wei Zhao <wei.zhao1 at intel.com>
> ---
>  app/test-pmd/cmdline_flow.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
> index 23ea7cc..515f95c 100644
> --- a/app/test-pmd/cmdline_flow.c
> +++ b/app/test-pmd/cmdline_flow.c
> @@ -4325,6 +4325,25 @@ parse_int(struct context *ctx, const struct token *token,
>  	}
>  	buf = (uint8_t *)ctx->object + arg->offset;
>  	size = arg->size;
> +	switch (size) {
> +	case sizeof(uint8_t):
> +		if (u > 0xff)
> +			return -1;
> +	case sizeof(uint16_t):
> +		if (u > 0xffff)
> +			return -1;
> +	case sizeof(uint8_t [3]):
> +		if (u > 0xffffff)
> +			return -1;
> +	case sizeof(uint32_t):
> +		if (u > 0xffffffff)
> +			return -1;
> +	case sizeof(uint64_t):
> +		if (u > 0xffffffffffffffff)
> +			return -1;
> +	default:
> +		break;
> +	}

Why just not something like:
if (u > RTE_LEN2MASK(size * CHAR_BIT))
   return -1;
?
Konstantin

>  objmask:
>  	switch (size) {
>  	case sizeof(uint8_t):
> --
> 2.7.5



More information about the dev mailing list