From d2e0fae69bf0695f526c9069acfa6e5d2ae5e178 Mon Sep 17 00:00:00 2001 From: David Hildenbrand Date: Tue, 18 Dec 2018 04:49:34 -0500 Subject: [PATCH] qapi: Fix string-input-visitor to reject NaN and infinities The string-input-visitor happily accepts NaN and infinities when parsing numbers (doubles). They shouldn't. Fix that. Also, add two test cases, testing if "NaN" and "inf" is properly rejected. Backports commit 4b69d4c3d7c133ebc9393ef3f86ce38831921cb6 from qemu --- qemu/qapi/string-input-visitor.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/qemu/qapi/string-input-visitor.c b/qemu/qapi/string-input-visitor.c index 4c94f550..5271414c 100644 --- a/qemu/qapi/string-input-visitor.c +++ b/qemu/qapi/string-input-visitor.c @@ -19,6 +19,7 @@ #include "qapi/qmp/qnull.h" #include "qemu/queue.h" #include "qemu/range.h" +#include "qemu/cutils.h" #include // strtoll @@ -297,12 +298,9 @@ static void parse_type_number(Visitor *v, const char *name, double *obj, Error **errp) { StringInputVisitor *siv = to_siv(v); - char *endp = (char *) siv->string; double val; - errno = 0; - val = strtod(siv->string, &endp); - if (errno || endp == siv->string || *endp) { + if (qemu_strtod_finite(siv->string, NULL, &val)) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "number"); return;