[AMD Official Use Only - AMD Internal Distribution Only]

Hi Huisong,

LGTM!

> -----Original Message-----
> From: Huisong Li <lihuis...@huawei.com>
> Sent: Friday, October 25, 2024 2:49 PM
> To: dev@dpdk.org
> Cc: m...@smartsharesystems.com; tho...@monjalon.net; Yigit, Ferruh
> <ferruh.yi...@amd.com>; anatoly.bura...@intel.com; david.h...@intel.com;
> Tummala, Sivaprasad <sivaprasad.tumm...@amd.com>;
> step...@networkplumber.org; konstantin.anan...@huawei.com;
> david.march...@redhat.com; fengcheng...@huawei.com;
> liuyongl...@huawei.com; lihuis...@huawei.com
> Subject: [PATCH v13 2/3] examples/l3fwd-power: fix data overflow when parse
> command line
>
> Caution: This message originated from an External Source. Use proper caution
> when opening attachments, clicking links, or responding.
>
>
> Many variables are 'uint32_t', like, 'pause_duration', 'scale_freq_min'
> and so on. They use parse_int() to parse it from command line.
> But overflow problem occurs when this function return.
>
> Fixes: 59f2853c4cae ("examples/l3fwd_power: add configuration options")
> Cc: sta...@dpdk.org
>
> Signed-off-by: Huisong Li <lihuis...@huawei.com>
> Acked-by: Konstantin Ananyev <konstantin.anan...@huawei.com>
> ---
>  examples/l3fwd-power/main.c | 36 ++++++++++++++++--------------------
>  1 file changed, 16 insertions(+), 20 deletions(-)
>
> diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c index
> 2bb6b092c3..0ce4aa04d4 100644
> --- a/examples/l3fwd-power/main.c
> +++ b/examples/l3fwd-power/main.c
> @@ -1525,7 +1525,7 @@ print_usage(const char *prgname)  }
>
>  static int
> -parse_int(const char *opt)
> +parse_uint32(const char *opt, uint32_t *res)
>  {
>         char *end = NULL;
>         unsigned long val;
> @@ -1535,23 +1535,14 @@ parse_int(const char *opt)
>         if ((opt[0] == '\0') || (end == NULL) || (*end != '\0'))
>                 return -1;
>
> -       return val;
> -}
> -
> -static int parse_max_pkt_len(const char *pktlen) -{
> -       char *end = NULL;
> -       unsigned long len;
> -
> -       /* parse decimal string */
> -       len = strtoul(pktlen, &end, 10);
> -       if ((pktlen[0] == '\0') || (end == NULL) || (*end != '\0'))
> +       if (val > UINT32_MAX) {
> +               RTE_LOG(ERR, L3FWD_POWER, "parameter shouldn't exceed
> + %u.\n", UINT32_MAX);
>                 return -1;
> +       }
>
> -       if (len == 0)
> -               return -1;
> +       *res = val;
>
> -       return len;
> +       return 0;
>  }
>
>  static int
> @@ -1898,8 +1889,9 @@ parse_args(int argc, char **argv)
>                         if (!strncmp(lgopts[option_index].name,
>                                         CMD_LINE_OPT_MAX_PKT_LEN,
>                                         sizeof(CMD_LINE_OPT_MAX_PKT_LEN))) {
> +                               if (parse_uint32(optarg, &max_pkt_len) != 0)
> +                                       return -1;
>                                 printf("Custom frame size is configured\n");
> -                               max_pkt_len = parse_max_pkt_len(optarg);
>                         }
>
>                         if (!strncmp(lgopts[option_index].name,
> @@ -1912,29 +1904,33 @@ parse_args(int argc, char **argv)
>                         if (!strncmp(lgopts[option_index].name,
>                                         CMD_LINE_OPT_MAX_EMPTY_POLLS,
>                                         
> sizeof(CMD_LINE_OPT_MAX_EMPTY_POLLS))) {
> +                               if (parse_uint32(optarg, &max_empty_polls) != 
> 0)
> +                                       return -1;
>                                 printf("Maximum empty polls configured\n");
> -                               max_empty_polls = parse_int(optarg);
>                         }
>
>                         if (!strncmp(lgopts[option_index].name,
>                                         CMD_LINE_OPT_PAUSE_DURATION,
>                                         sizeof(CMD_LINE_OPT_PAUSE_DURATION))) 
> {
> +                               if (parse_uint32(optarg, &pause_duration) != 
> 0)
> +                                       return -1;
>                                 printf("Pause duration configured\n");
> -                               pause_duration = parse_int(optarg);
>                         }
>
>                         if (!strncmp(lgopts[option_index].name,
>                                         CMD_LINE_OPT_SCALE_FREQ_MIN,
>                                         sizeof(CMD_LINE_OPT_SCALE_FREQ_MIN))) 
> {
> +                               if (parse_uint32(optarg, &scale_freq_min) != 
> 0)
> +                                       return -1;
>                                 printf("Scaling frequency minimum 
> configured\n");
> -                               scale_freq_min = parse_int(optarg);
>                         }
>
>                         if (!strncmp(lgopts[option_index].name,
>                                         CMD_LINE_OPT_SCALE_FREQ_MAX,
>                                         sizeof(CMD_LINE_OPT_SCALE_FREQ_MAX))) 
> {
> +                               if (parse_uint32(optarg, &scale_freq_max) != 
> 0)
> +                                       return -1;
>                                 printf("Scaling frequency maximum 
> configured\n");
> -                               scale_freq_max = parse_int(optarg);
>                         }
>
>                         break;
> --
> 2.22.0
Acked-by: Sivaprasad Tummala <sivaprasad.tumm...@amd.com>

Reply via email to