From patchwork Thu Aug 23 16:39:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 961502 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41x9ZS033dz9s2P for ; Fri, 24 Aug 2018 02:57:35 +1000 (AEST) Received: from localhost ([::1]:37779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fssvN-0003NW-Fz for incoming@patchwork.ozlabs.org; Thu, 23 Aug 2018 12:57:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fssgP-0003T9-EC for qemu-devel@nongnu.org; Thu, 23 Aug 2018 12:42:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsses-0003Y2-Vw for qemu-devel@nongnu.org; Thu, 23 Aug 2018 12:40:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44724 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 1fsses-0003XJ-M5 for qemu-devel@nongnu.org; Thu, 23 Aug 2018 12:40:30 -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 452AB40216ED; Thu, 23 Aug 2018 16:40:30 +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 EFC572157F4A; Thu, 23 Aug 2018 16:40:29 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id CEB6F11329EE; Thu, 23 Aug 2018 18:40:25 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 23 Aug 2018 18:39:37 +0200 Message-Id: <20180823164025.12553-11-armbru@redhat.com> In-Reply-To: <20180823164025.12553-1-armbru@redhat.com> References: <20180823164025.12553-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.5]); Thu, 23 Aug 2018 16:40:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 23 Aug 2018 16:40:30 +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] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v3 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: , Cc: marcandre.lureau@redhat.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 --- 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[] = { { "\\b\\f\\n\\r\\t\\\\\\\"", "\b\f\n\r\t\\\"" }, - { "\\/", "/", .skip = 1 }, + { "\\/\\'", "/'", .skip = 1 }, { "single byte utf-8 \\u0020", "single byte utf-8 ", .skip = 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 = 1 }, + { "\\", NULL }, + { "\\z", NULL }, + { "\\ux", NULL }, + { "\\u1x", NULL }, + { "\\u12x", NULL }, + { "\\u123x", NULL }, + { "\\u12345", "\341\210\2645" }, + { "\\u0000x", "x", .skip = 1}, /* bug: want \xC0\x80x */ + { "unpaired leading surrogate \\uD800", + /* bug: not rejected */ + "unpaired leading surrogate \355\240\200", .skip = 1 }, + { "unpaired leading surrogate \\uD800\\uCAFE", + /* bug: not rejected */ + "unpaired leading surrogate \355\240\200\354\253\276", .skip = 1 }, + { "unpaired leading surrogate \\uD800\\uD801\\uDC02", + /* bug: not rejected */ + "unpaired leading surrogate \355\240\200\355\240\201\355\260\202", + .skip = 1 }, + { "unpaired trailing surrogate \\uDC00", + /* bug: not rejected */ + "unpaired trailing surrogate \355\260\200", .skip = 1}, + { "backward surrogate pair \\uDC00\\uD800", + /* bug: not rejected */ + "backward surrogate pair \355\260\200\355\240\200", .skip = 1}, + { "noncharacter U+FDD0 \\uFDD0", + /* bug: not rejected */ + "noncharacter U+FDD0 \xEF\xB7\x90", .skip = 1}, + { "noncharacter U+FDEF \\uFDEF", + /* bug: not rejected */ + "noncharacter U+FDEF \xEF\xB7\xAF", .skip = 1}, + { "noncharacter U+1FFFE \\uD87F\\uDFFE", + /* bug: not rejected */ + "noncharacter U+1FFFE \xED\xA1\xBF\xED\xBF\xBE", .skip = 1}, + { "noncharacter U+10FFFF \\uDC3F\\uDFFF", + /* bug: not rejected */ + "noncharacter U+10FFFF \xED\xB0\xBF\xED\xBF\xBF", .skip = 1}, {} }; int i, j; @@ -69,15 +108,20 @@ static void escaped_string(void) for (i = 0; test_cases[i].json_in; i++) { for (j = 0; j < 2; j++) { - cstr = from_json_str(test_cases[i].json_in, j, &error_abort); - g_assert_cmpstr(qstring_get_try_str(cstr), - ==, test_cases[i].utf8_out); - if (test_cases[i].skip == 0) { - jstr = to_json_str(cstr); - g_assert_cmpstr(jstr, ==, test_cases[i].json_in); - g_free(jstr); + if (test_cases[i].utf8_out) { + cstr = from_json_str(test_cases[i].json_in, j, &error_abort); + g_assert_cmpstr(qstring_get_try_str(cstr), + ==, test_cases[i].utf8_out); + if (!test_cases[i].skip) { + jstr = to_json_str(cstr); + g_assert_cmpstr(jstr, ==, test_cases[i].json_in); + g_free(jstr); + } + qobject_unref(cstr); + } else { + cstr = from_json_str(test_cases[i].json_in, j, NULL); + g_assert(!cstr); } - qobject_unref(cstr); } } }