From nobody Wed Nov 5 10:44:09 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 1533730685166679.8979964558371; Wed, 8 Aug 2018 05:18:05 -0700 (PDT) Received: from localhost ([::1]:43236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnNPg-00027f-48 for importer@patchew.org; Wed, 08 Aug 2018 08:18:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnNBn-0006gd-6S for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnNBj-0008Tx-Cj for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:43 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47708 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 1fnNBj-0008S8-64 for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:03:39 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99B7079D41; 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 6DC8220180F8; Wed, 8 Aug 2018 12:03:38 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7436011386C3; Wed, 8 Aug 2018 14:03:34 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 8 Aug 2018 14:03:02 +0200 Message-Id: <20180808120334.10970-25-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.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 08 Aug 2018 12:03:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Wed, 08 Aug 2018 12:03:38 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 24/56] json: Accept overlong \xC0\x80 as U+0000 ("modified UTF-8") 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" This is consistent with qobject_to_json(). See commit e2ec3f97680. Signed-off-by: Markus Armbruster --- qobject/json-lexer.c | 2 +- qobject/json-parser.c | 2 +- tests/check-qjson.c | 8 +------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c index ca1e0e2c03..36fb665b12 100644 --- a/qobject/json-lexer.c +++ b/qobject/json-lexer.c @@ -93,7 +93,7 @@ * interpolation =3D %((l|ll|I64)[du]|[ipsf]) * * Note: - * - Input must be encoded in UTF-8. + * - Input must be encoded in modified UTF-8. * - Decoding and validating is left to the parser. */ =20 diff --git a/qobject/json-parser.c b/qobject/json-parser.c index b3a95be3c8..14225c3c09 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -199,7 +199,7 @@ static QString *qstring_from_escaped_str(JSONParserCont= ext *ctxt, } } else { cp =3D mod_utf8_codepoint(ptr, 6, &end); - if (cp <=3D 0) { + if (cp < 0) { parse_error(ctxt, token, "invalid UTF-8 sequence in string= "); goto out; } diff --git a/tests/check-qjson.c b/tests/check-qjson.c index e00be5b023..e5a7cb6bf6 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -121,12 +121,6 @@ static void escaped_string(void) static void utf8_string(void) { /* - * Problem: we can't easily deal with embedded U+0000. Parsing - * the JSON string "this \\u0000" is fun" yields "this \0 is fun", - * which gets misinterpreted as NUL-terminated "this ". We should - * consider using overlong encoding \xC0\x80 for U+0000 ("modified - * UTF-8"). - * * Most test cases are scraped from Markus Kuhn's UTF-8 decoder * capability and stress test at * http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt @@ -555,7 +549,7 @@ static void utf8_string(void) { /* \U+0000 */ "\xC0\x80", - NULL, + "\xC0\x80", "\\u0000", }, { --=20 2.17.1