From nobody Wed Nov 5 10:44:11 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533731201160296.7708349010783; Wed, 8 Aug 2018 05:26:41 -0700 (PDT) Received: from localhost ([::1]:43310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnNY0-0001Lt-1n for importer@patchew.org; Wed, 08 Aug 2018 08:26:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52393) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnNBl-0006f9-M0 for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnNBi-0008SY-UL for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51054 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fnNBi-0008RE-L5 for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:38 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2CD25402346C; Wed, 8 Aug 2018 12:03:38 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-117-62.ams2.redhat.com [10.36.117.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D64422166BA0; Wed, 8 Aug 2018 12:03:37 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 37D8B113866C; Wed, 8 Aug 2018 14:03:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 8 Aug 2018 14:02:51 +0200 Message-Id: <20180808120334.10970-14-armbru@redhat.com> In-Reply-To: <20180808120334.10970-1-armbru@redhat.com> References: <20180808120334.10970-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 08 Aug 2018 12:03:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 08 Aug 2018 12:03:38 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 13/56] check-qjson: Fix utf8_string() to test all invalid sequences 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: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Some of utf8_string()'s test_cases[] contain multiple invalid sequences. Testing that qobject_from_json() fails only tests we reject at least one invalid sequence. That's incomplete. Additionally test each non-space sequence in isolation. This demonstrates that the JSON parser accepts invalid sequences starting with \xC2..\xF4. Add a FIXME comment. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- tests/check-qjson.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 5ba09e5ab6..5f3334322b 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -20,6 +20,7 @@ #include "qapi/qmp/qnull.h" #include "qapi/qmp/qnum.h" #include "qapi/qmp/qstring.h" +#include "qemu/unicode.h" #include "qemu-common.h" =20 static QString *from_json_str(const char *jstr, Error **errp, bool single) @@ -379,7 +380,7 @@ static void utf8_string(void) "\xC8 \xC9 \xCA \xCB \xCC \xCD \xCE \xCF " "\xD0 \xD1 \xD2 \xD3 \xD4 \xD5 \xD6 \xD7 " "\xD8 \xD9 \xDA \xDB \xDC \xDD \xDE \xDF ", - NULL, /* bug: rejected */ + NULL, /* bug: rejected (partly, see FIXME below)= */ "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFF= FD " "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFF= FD " "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFF= FD " @@ -398,7 +399,7 @@ static void utf8_string(void) /* 3.2.3 All 8 first bytes of 4-byte sequences, followed by space= */ { "\xF0 \xF1 \xF2 \xF3 \xF4 \xF5 \xF6 \xF7 ", - NULL, /* bug: rejected */ + NULL, /* bug: rejected (partly, see FIXME below)= */ "\\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFFFD \\uFF= FD ", }, /* 3.2.4 All 4 first bytes of 5-byte sequences, followed by space= */ @@ -478,7 +479,7 @@ static void utf8_string(void) { "\xC0\xE0\x80\xF0\x80\x80\xF8\x80\x80\x80\xFC\x80\x80\x80\x80" "\xDF\xEF\xBF\xF7\xBF\xBF\xFB\xBF\xBF\xBF\xFD\xBF\xBF\xBF\xBF", - NULL, /* bug: rejected */ + NULL, /* bug: rejected (partly, see FIXME below)= */ "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD" "\\uFFFD\\uFFFD\\uFFFD\\uFFFD\\uFFFD", }, @@ -761,8 +762,8 @@ static void utf8_string(void) }; int i, j; QString *str; - const char *json_in, *utf8_out, *utf8_in, *json_out; - char *jstr; + const char *json_in, *utf8_out, *utf8_in, *json_out, *tail; + char *end, *in, *jstr; =20 for (i =3D 0; test_cases[i].json_in; i++) { for (j =3D 0; j < 2; j++) { @@ -779,6 +780,28 @@ static void utf8_string(void) } else { str =3D from_json_str(json_in, NULL, j); g_assert(!str); + /* + * Failure may be due to any sequence, but *all* sequences + * are expected to fail. Test each one in isolation. + */ + for (tail =3D json_in; *tail; tail =3D end) { + mod_utf8_codepoint(tail, 6, &end); + if (*end =3D=3D ' ') { + end++; + } + in =3D strndup(tail, end - tail); + str =3D from_json_str(in, NULL, j); + /* + * FIXME JSON parser accepts invalid sequence + * starting with \xC2..\xF4 + */ + if (*in >=3D '\xC2' && *in <=3D '\xF4') { + g_free(str); + str =3D NULL; + } + g_assert(!str); + g_free(in); + } } =20 /* Unparse @utf8_in, expect @json_out */ --=20 2.17.1