net: fix assertion failure when ipv6-prefixlen is not a number

If 'ipv6-prefixlen' is not a number, the current behaviour
produces an assertion failure:
    $ qemu-system-x86_64 -net user,ipv6-net=feca::0/a
    qemu-system-x86_64: qemu/util/qemu-option.c:1175: qemu_opts_foreach:
    Assertion `!errp || !*errp' failed.
    Aborted (core dumped)

This patch fixes it, jumping to the end of the function when
'ipv6-prefixlen' is not a number, and printing the more friendly
message:
    $ qemu-system-x86_64 -net user,ipv6-net=feca::0/a
    qemu-system-x86_64: Parameter 'ipv6-prefixlen' expects a number

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
This commit is contained in:
Stefano Garzarella 2019-05-17 15:47:45 +02:00 committed by Jason Wang
parent 59377b4a4b
commit 21c520d0c1
1 changed files with 5 additions and 4 deletions

View File

@ -1136,11 +1136,11 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
if (err) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
"ipv6-prefix", "a number");
} else {
qemu_opt_set_number(opts, "ipv6-prefixlen", len,
&error_abort);
"ipv6-prefixlen", "a number");
goto out;
}
qemu_opt_set_number(opts, "ipv6-prefixlen", len, &error_abort);
}
qemu_opt_unset(opts, "ipv6-net");
}
@ -1162,6 +1162,7 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
qapi_free_NetLegacy(object);
}
out:
error_propagate(errp, err);
visit_free(v);
return ret;