On Fri, 22 Aug 2025 08:14:30 -0400
Khadem Ullah <14pwcse1...@uetpeshawar.edu.pk> wrote:

> Add validation mechanism for meter creation. The maximum
> possible entries are
> [<dscp_tbl_entry0> <dscp_tbl_entry1> ...<dscp_tbl_entry63>]
> [<vlan_tbl_entry0> <vlan_tbl_entry1> ... <vlan_tbl_entry15>].
> Currently, testpmd allows any input table entries for dscp
> and vlan tables.
> 
> This patch validates the maximum possible dscp and vlan table
> entries for meter creation.
> 
> Fixes: 9f5488e326d3b ("app/testpmd: support different input color method")
> Cc: sta...@dpdk.org
> 
> Signed-off-by: Khadem Ullah <14pwcse1...@uetpeshawar.edu.pk>
> ---
>  app/test-pmd/cmdline_mtr.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c
> index e16c5b268f..1435645c1a 100644
> --- a/app/test-pmd/cmdline_mtr.c
> +++ b/app/test-pmd/cmdline_mtr.c
> @@ -85,14 +85,33 @@ parse_uint(uint64_t *value, const char *str)
>       return 0;
>  }
>  
> +static int
> +validate_input_color_table_entries(char *str)
> +{
> +     char *token;
> +     int i = 0;

Useless initialization

> +     token = strtok_r(str, PARSE_DELIMITER, &str);
> +     for (i = 0; token != NULL; i++)
> +             token = strtok_r(str, PARSE_DELIMITER, &str);

Rather than parsing all the way to the end, why not put the max test inside the 
loop

> +     if (i > (MAX_DSCP_TABLE_ENTRIES + MAX_VLAN_TABLE_ENTRIES))
> +             return -1;
> +     else
> +             return 0;
> +}
> +
>  static int
>  parse_input_color_table_entries(char *str, enum rte_color **dscp_table,
>       enum rte_color **vlan_table)
>  {
>       enum rte_color *vlan, *dscp;
>       char *token;
> +     char *temp_str = strdup(str);
>       int i = 0;
>  
> +     if (validate_input_color_table_entries(temp_str))
> +             return -1;
> +

On error, this leaks the temporary string created (temp_str).


Reply via email to