diff mbox

qemu-option: reject empty number value

Message ID 20170206132835.9440-1-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Feb. 6, 2017, 1:28 p.m. UTC
When no number is provided, return an invalid number error.
(note: this may break some users relying on default 0 value)

Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1417864

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 util/qemu-option.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Eric Blake Feb. 6, 2017, 6:19 p.m. UTC | #1
On 02/06/2017 07:28 AM, Marc-André Lureau wrote:
> When no number is provided, return an invalid number error.
> (note: this may break some users relying on default 0 value)

Anyone that writes 'size=' instead of 'size=0' deserves the breakage.

> 
> Fixes:
> https://bugzilla.redhat.com/show_bug.cgi?id=1417864
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  util/qemu-option.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Eric Blake <eblake@redhat.com>
Markus Armbruster Feb. 20, 2017, 1:25 p.m. UTC | #2
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> When no number is provided, return an invalid number error.
> (note: this may break some users relying on default 0 value)
>
> Fixes:
> https://bugzilla.redhat.com/show_bug.cgi?id=1417864
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  util/qemu-option.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/util/qemu-option.c b/util/qemu-option.c
> index 3467dc2397..89afa4b2c3 100644
> --- a/util/qemu-option.c
> +++ b/util/qemu-option.c
> @@ -150,7 +150,7 @@ static void parse_option_number(const char *name, const char *value,
>  
>      if (value != NULL) {
>          number = strtoull(value, &postfix, 0);
> -        if (*postfix != '\0') {
> +        if (*postfix != '\0' || postfix == value) {
>              error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number");
>              return;
>          }

My "[PATCH 09/24] QemuOpts: Fix to reject numbers that overflow
uint64_t" is a more comprehensive fix, even though I missed this case
both in the tests and the commit message.  I'll take care of that in v2.

Thanks!
diff mbox

Patch

diff --git a/util/qemu-option.c b/util/qemu-option.c
index 3467dc2397..89afa4b2c3 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -150,7 +150,7 @@  static void parse_option_number(const char *name, const char *value,
 
     if (value != NULL) {
         number = strtoull(value, &postfix, 0);
-        if (*postfix != '\0') {
+        if (*postfix != '\0' || postfix == value) {
             error_setg(errp, QERR_INVALID_PARAMETER_VALUE, name, "a number");
             return;
         }