[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Libguestfs] [PATCH nbdkit v2] server: utils: Make nbdkit_parse_size to reject negative values



On 2/8/19 12:10 AM, Mykola Ivanets wrote:
> From: Nikolay Ivanets <stenavin gmail com>

Grammar in the subject: s/ to//

> 
> nbdkit_parse_size() uses strtoumax() function to parse input strings
> which states:
> 

> 1. Some more tests were added to cover described behaviour.
> 
> 2. Input strings where grouped into a set which lead to
> valid/invalid/negative/overflow result.
> 
> 3. Some strings with a leading '+' sign were added.
> ---

>    errno = 0;
> -  size = strtoumax (str, &end, 10);
> -  if (errno || str == end) {
> +  size = strtoimax (str, &end, 10);
> +  if (str == end) {
>      nbdkit_error ("could not parse size string (%s)", str);
>      return -1;
>    }
> +  if (size < 0) {
> +    nbdkit_error ("size cannot be negative (%s)", str);
> +    return -1;
> +  }
> +  if (errno) {
> +    nbdkit_error ("size (%s) exceeds maximum value", str);
> +    return -1;
> +  }

On underflow, strtoimax returns INTMAX_MIN and sets ERANGE; which favors
a message about negative values over a message about overflow. Swapping
the errno message first would also work, but I'm fine with your approach.

Thanks; pushed!

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]