qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 02/24] QemuOpts: Assert value string isn't null


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 02/24] QemuOpts: Assert value string isn't null
Date: Tue, 14 Feb 2017 14:10:17 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0

On 02/14/2017 04:25 AM, Markus Armbruster wrote:
> Plenty of code relies on QemuOpt member @str not being null, including
> qemu_opts_print(), qemu_opts_to_qdict(), and callbacks passed to
> qemu_opt_foreach().
> 

> 
> Assert member @str isn't null, so that misuse is caught right away.
> 
> Simplify parse_option_bool(), parse_option_number() and
> parse_option_size() accordingly.  Best viewed with whitespace changes
> ignored.
> 
> Signed-off-by: Markus Armbruster <address@hidden>
> ---
>  util/qemu-option.c | 89 
> ++++++++++++++++++++++++------------------------------
>  1 file changed, 39 insertions(+), 50 deletions(-)
> 

> @@ -180,39 +172,35 @@ void parse_option_size(const char *name, const char 
> *value,
>      char *postfix;
>      double sizef;
>  

> +    sizef = strtod(value, &postfix);
> +    if (sizef < 0 || sizef > UINT64_MAX) {
> +        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name,
> +                   "a non-negative number below 2^64");
> +        return;
> +    }
> +    switch (*postfix) {
> +    case 'T':
...
> +    default:
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
> +        error_append_hint(errp, "You may use k, M, G or T suffixes for "
> +                          "kilobytes, megabytes, gigabytes and 
> terabytes.\n");
> +        return;
>      }

Unrelated to this patch, but noticing it now: it looks like we blindly
accept "qemu-system-x86_64 -nodefaults -m 1Mgarbage" as meaning the same
as "... -m 1M".  Looking back at 1/24, looks like you marked that as one
of the buggy cases.  Good - I guess I'll get to comment more on it in a
later patch.

Reviewed-by: Eric Blake <address@hidden>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]