[dpdk-dev] [PATCH 1/8] examples/fips_validation: enhance getopt_long usage
David Marchand
david.marchand at redhat.com
Tue Nov 10 09:23:42 CET 2020
On Tue, Nov 10, 2020 at 7:10 AM Ibtisam Tariq <ibtisam.tariq at emumba.com> wrote:
> IMHO, it cannot be moved to read_uint16 parser.
> If we do, we can't verify that the user input value is greater than
> UINT16 MAX or not on the overflow data.
> > > + if (data_room_size == 0 ||
> > > + data_room_size > UINT16_MAX) {
> > > + cryptodev_fips_validate_usage(prgname);
> > > + return -EINVAL;
> > > + }
>
> The temp variable:data_room_size is necessary to check the overflow of
> the command line argument.
The overflow check can go to a new read_uint16 parser, like what is
done in other parsers in this example.
int
parser_read_uint32(uint32_t *value, char *p)
{
uint64_t val = 0;
int ret = parser_read_uint64(&val, p);
if (ret < 0)
return ret;
if (val > UINT32_MAX)
return -EINVAL;
*value = val;
return 0;
}
The parser_read_uint16 caller can do any additional check, here test
for 0 value.
--
David Marchand
More information about the dev
mailing list