[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 01/45] qobject-input-visitor: Reject non-finite n
From: |
Marc-André Lureau |
Subject: |
[Qemu-devel] [PATCH v2 01/45] qobject-input-visitor: Reject non-finite numbers with keyval |
Date: |
Wed, 31 May 2017 17:56:25 +0400 |
From: Markus Armbruster <address@hidden>
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 <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Marc-André Lureau <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
qapi/qobject-input-visitor.c | 3 ++-
tests/test-qobject-input-visitor.c | 6 ++++++
2 files changed, 8 insertions(+), 1 deletion(-)
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 <math.h>
#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");
diff --git a/tests/test-qobject-input-visitor.c
b/tests/test-qobject-input-visitor.c
index f965743b6e..e2aabbe972 100644
--- a/tests/test-qobject-input-visitor.c
+++ b/tests/test-qobject-input-visitor.c
@@ -278,11 +278,17 @@ static void
test_visitor_in_number_str_keyval(TestInputVisitorData *data,
{
double res = 0, value = 3.14;
Visitor *v;
+ Error *err = NULL;
v = visitor_input_test_init_full(data, true, "\"3.14\"");
visit_type_number(v, NULL, &res, &error_abort);
g_assert_cmpfloat(res, ==, value);
+
+ v = visitor_input_test_init_full(data, true, "\"inf\"");
+
+ visit_type_number(v, NULL, &res, &err);
+ error_free_or_abort(&err);
}
static void test_visitor_in_number_str_fail(TestInputVisitorData *data,
--
2.13.0.91.g00982b8dd
- [Qemu-devel] [PATCH v2 00/45] qobject/qapi: add uint type, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 01/45] qobject-input-visitor: Reject non-finite numbers with keyval,
Marc-André Lureau <=
- [Qemu-devel] [PATCH v2 02/45] qapi: Document visit_type_any() issues with keyval input, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 03/45] tests/qapi-schema: Avoid 'str' in alternate test cases, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 04/45] qapi: Reject alternates that can't work with keyval_parse(), Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 05/45] qdev: remove PropertyInfo.qtype field, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 06/45] object: fix potential leak in getters, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 07/45] tests: remove alt num-int cases, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 08/45] tests: add more int/number ranges checks, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 10/45] qapi: Remove visit_start_alternate() parameter promote_int, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 09/45] qapi: merge QInt and QFloat in QNum, Marc-André Lureau, 2017/05/31
- [Qemu-devel] [PATCH v2 11/45] tests: remove /qnum/destroy test, Marc-André Lureau, 2017/05/31