On Tue, Nov 10, 2020 at 7:10 AM Ibtisam Tariq <ibtisam.ta...@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

Reply via email to