From 5891c388bbdd48ba0440d2738155f364589a432a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 22 May 2017 18:42:12 +0200 Subject: qobject-input-visitor: Reject non-finite numbers with keyval The QObject input visitor can produce only finite numbers when its input comes out of the JSON parser, because the the JSON parser implements RFC 7159, which provides no syntax for infinity and NaN. However, it can produce infinity and NaN when its input comes out of keyval_parse(), because we parse with strtod() then. The keyval variant should not be able to express things the JSON variant can't. Rejecting non-finite numbers there is the conservative fix. It's also minimally invasive. We could instead extend our JSON dialect to provide for infinity and NaN. Not today. Note that the JSON formatter can emit non-finite numbers (marked FIXME in commit 6e8e5cb). Signed-off-by: Markus Armbruster Message-Id: <1495471335-23707-2-git-send-email-armbru@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Marc-André Lureau --- qapi/qobject-input-visitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'qapi/qobject-input-visitor.c') diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index d0f0002317..eac40f618a 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -13,6 +13,7 @@ */ #include "qemu/osdep.h" +#include #include "qapi/error.h" #include "qapi/qobject-input-visitor.h" #include "qapi/visitor-impl.h" @@ -568,7 +569,7 @@ static void qobject_input_type_number_keyval(Visitor *v, const char *name, errno = 0; *obj = strtod(str, &endp); - if (errno || endp == str || *endp) { + if (errno || endp == str || *endp || !isfinite(*obj)) { /* TODO report -ERANGE more nicely */ error_setg(errp, QERR_INVALID_PARAMETER_TYPE, full_name(qiv, name), "number"); -- cgit v1.2.3-55-g7522