From nobody Wed Nov 5 16:36:22 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 153514040990496.89675390893046; Fri, 24 Aug 2018 12:53:29 -0700 (PDT) Received: from localhost ([::1]:43288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftI94-0004A0-V9 for importer@patchew.org; Fri, 24 Aug 2018 15:53:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftHoi-0002HZ-Ab for qemu-devel@nongnu.org; Fri, 24 Aug 2018 15:32:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftHoe-0001ft-Hz for qemu-devel@nongnu.org; Fri, 24 Aug 2018 15:32:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55054 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 1ftHoc-0001Yg-4f for qemu-devel@nongnu.org; Fri, 24 Aug 2018 15:32:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AD0440216F4 for ; Fri, 24 Aug 2018 19:32:09 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-97.ams2.redhat.com [10.36.116.97]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CE9B31010417 for ; Fri, 24 Aug 2018 19:32:08 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id A29A011329EE; Fri, 24 Aug 2018 21:32:06 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 24 Aug 2018 21:31:18 +0200 Message-Id: <20180824193206.25475-11-armbru@redhat.com> In-Reply-To: <20180824193206.25475-1-armbru@redhat.com> References: <20180824193206.25475-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 24 Aug 2018 19:32:09 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 24 Aug 2018 19:32:09 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.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] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 10/58] check-qjson: Cover escaped characters more thoroughly, part 2 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: , 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" Cover escaped single quote, surrogates, invalid escapes, and noncharacters. This demonstrates that valid surrogate pairs are misinterpreted, and invalid surrogates and noncharacters aren't rejected. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Message-Id: <20180823164025.12553-11-armbru@redhat.com> --- tests/check-qjson.c | 62 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/tests/check-qjson.c b/tests/check-qjson.c index 880453a93b..4bb4925673 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -57,10 +57,49 @@ static void escaped_string(void) int skip; } test_cases[] =3D { { "\\b\\f\\n\\r\\t\\\\\\\"", "\b\f\n\r\t\\\"" }, - { "\\/", "/", .skip =3D 1 }, + { "\\/\\'", "/'", .skip =3D 1 }, { "single byte utf-8 \\u0020", "single byte utf-8 ", .skip =3D 1 = }, { "double byte utf-8 \\u00A2", "double byte utf-8 \xc2\xa2" }, { "triple byte utf-8 \\u20AC", "triple byte utf-8 \xe2\x82\xac" }, + { "quadruple byte utf-8 \\uD834\\uDD1E", /* U+1D11E */ + /* bug: want \xF0\x9D\x84\x9E */ + "quadruple byte utf-8 \xED\xA0\xB4\xED\xB4\x9E", .skip =3D 1 }, + { "\\", NULL }, + { "\\z", NULL }, + { "\\ux", NULL }, + { "\\u1x", NULL }, + { "\\u12x", NULL }, + { "\\u123x", NULL }, + { "\\u12345", "\341\210\2645" }, + { "\\u0000x", "x", .skip =3D 1}, /* bug: want \xC0\x80x */ + { "unpaired leading surrogate \\uD800", + /* bug: not rejected */ + "unpaired leading surrogate \355\240\200", .skip =3D 1 }, + { "unpaired leading surrogate \\uD800\\uCAFE", + /* bug: not rejected */ + "unpaired leading surrogate \355\240\200\354\253\276", .skip =3D= 1 }, + { "unpaired leading surrogate \\uD800\\uD801\\uDC02", + /* bug: not rejected */ + "unpaired leading surrogate \355\240\200\355\240\201\355\260\202= ", + .skip =3D 1 }, + { "unpaired trailing surrogate \\uDC00", + /* bug: not rejected */ + "unpaired trailing surrogate \355\260\200", .skip =3D 1}, + { "backward surrogate pair \\uDC00\\uD800", + /* bug: not rejected */ + "backward surrogate pair \355\260\200\355\240\200", .skip =3D 1}, + { "noncharacter U+FDD0 \\uFDD0", + /* bug: not rejected */ + "noncharacter U+FDD0 \xEF\xB7\x90", .skip =3D 1}, + { "noncharacter U+FDEF \\uFDEF", + /* bug: not rejected */ + "noncharacter U+FDEF \xEF\xB7\xAF", .skip =3D 1}, + { "noncharacter U+1FFFE \\uD87F\\uDFFE", + /* bug: not rejected */ + "noncharacter U+1FFFE \xED\xA1\xBF\xED\xBF\xBE", .skip =3D 1}, + { "noncharacter U+10FFFF \\uDC3F\\uDFFF", + /* bug: not rejected */ + "noncharacter U+10FFFF \xED\xB0\xBF\xED\xBF\xBF", .skip =3D 1}, {} }; int i, j; @@ -69,15 +108,20 @@ static void escaped_string(void) =20 for (i =3D 0; test_cases[i].json_in; i++) { for (j =3D 0; j < 2; j++) { - cstr =3D from_json_str(test_cases[i].json_in, j, &error_abort); - g_assert_cmpstr(qstring_get_try_str(cstr), - =3D=3D, test_cases[i].utf8_out); - if (test_cases[i].skip =3D=3D 0) { - jstr =3D to_json_str(cstr); - g_assert_cmpstr(jstr, =3D=3D, test_cases[i].json_in); - g_free(jstr); + if (test_cases[i].utf8_out) { + cstr =3D from_json_str(test_cases[i].json_in, j, &error_ab= ort); + g_assert_cmpstr(qstring_get_try_str(cstr), + =3D=3D, test_cases[i].utf8_out); + if (!test_cases[i].skip) { + jstr =3D to_json_str(cstr); + g_assert_cmpstr(jstr, =3D=3D, test_cases[i].json_in); + g_free(jstr); + } + qobject_unref(cstr); + } else { + cstr =3D from_json_str(test_cases[i].json_in, j, NULL); + g_assert(!cstr); } - qobject_unref(cstr); } } } --=20 2.17.1