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
This commit is contained in:
David Hildenbrand 2018-12-18 04:49:34 -05:00 committed by Lioncash
parent 67f9141b13
commit d2e0fae69b
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -19,6 +19,7 @@
#include "qapi/qmp/qnull.h" #include "qapi/qmp/qnull.h"
#include "qemu/queue.h" #include "qemu/queue.h"
#include "qemu/range.h" #include "qemu/range.h"
#include "qemu/cutils.h"
#include <stdlib.h> // strtoll #include <stdlib.h> // strtoll
@ -297,12 +298,9 @@ static void parse_type_number(Visitor *v, const char *name, double *obj,
Error **errp) Error **errp)
{ {
StringInputVisitor *siv = to_siv(v); StringInputVisitor *siv = to_siv(v);
char *endp = (char *) siv->string;
double val; double val;
errno = 0; if (qemu_strtod_finite(siv->string, NULL, &val)) {
val = strtod(siv->string, &endp);
if (errno || endp == siv->string || *endp) {
error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"number"); "number");
return; return;