From nobody Thu Nov 6 19:28:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 154281899234255.51942831639349; Wed, 21 Nov 2018 08:49:52 -0800 (PST) Received: from localhost ([::1]:40184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPVhB-0002b3-Ru for importer@patchew.org; Wed, 21 Nov 2018 11:49:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPVc8-0007Qk-Cy for qemu-devel@nongnu.org; Wed, 21 Nov 2018 11:44:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPVc7-0006c1-N5 for qemu-devel@nongnu.org; Wed, 21 Nov 2018 11:44:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40940) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPVc7-0006ax-Hz for qemu-devel@nongnu.org; Wed, 21 Nov 2018 11:44:31 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5D64394D29; Wed, 21 Nov 2018 16:44:30 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-177.ams2.redhat.com [10.36.116.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81B035C21E; Wed, 21 Nov 2018 16:44:29 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Wed, 21 Nov 2018 17:44:15 +0100 Message-Id: <20181121164421.20780-4-david@redhat.com> In-Reply-To: <20181121164421.20780-1-david@redhat.com> References: <20181121164421.20780-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 21 Nov 2018 16:44:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 for-4.0 3/9] qapi: Fix string-input-visitor to reject NaN and infinities X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , David Hildenbrand , Markus Armbruster , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: David Hildenbrand --- qapi/string-input-visitor.c | 6 ++---- tests/test-string-input-visitor.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c index b3fdd0827d..b89c6c4e06 100644 --- a/qapi/string-input-visitor.c +++ b/qapi/string-input-visitor.c @@ -20,6 +20,7 @@ #include "qemu/option.h" #include "qemu/queue.h" #include "qemu/range.h" +#include "qemu/cutils.h" =20 =20 struct StringInputVisitor @@ -313,12 +314,9 @@ static void parse_type_number(Visitor *v, const char *= name, double *obj, Error **errp) { StringInputVisitor *siv =3D to_siv(v); - char *endp =3D (char *) siv->string; double val; =20 - errno =3D 0; - val =3D strtod(siv->string, &endp); - if (errno || endp =3D=3D siv->string || *endp) { + if (qemu_strtod_finite(siv->string, NULL, &val)) { error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", "number"); return; diff --git a/tests/test-string-input-visitor.c b/tests/test-string-input-vi= sitor.c index 88e0e1aa9a..1efba06948 100644 --- a/tests/test-string-input-visitor.c +++ b/tests/test-string-input-visitor.c @@ -252,6 +252,19 @@ static void test_visitor_in_number(TestInputVisitorDat= a *data, visit_type_number(v, NULL, &res, &err); g_assert(!err); g_assert_cmpfloat(res, =3D=3D, value); + + /* NaN and infinity has to be rejected */ + + v =3D visitor_input_test_init(data, "NaN"); + + visit_type_number(v, NULL, &res, &err); + error_free_or_abort(&err); + + v =3D visitor_input_test_init(data, "inf"); + + visit_type_number(v, NULL, &res, &err); + error_free_or_abort(&err); + } =20 static void test_visitor_in_string(TestInputVisitorData *data, --=20 2.17.2