From nobody Mon Feb 9 02:27:57 2026 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488195144927631.5423621130948; Mon, 27 Feb 2017 03:32:24 -0800 (PST) Received: from localhost ([::1]:51824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciJXS-0007nG-Gg for importer@patchew.org; Mon, 27 Feb 2017 06:32:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciJMY-00069S-Ef for qemu-devel@nongnu.org; Mon, 27 Feb 2017 06:21:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciJMU-00012n-PE for qemu-devel@nongnu.org; Mon, 27 Feb 2017 06:21:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51316) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciJMN-0000u7-8v; Mon, 27 Feb 2017 06:20:55 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E513C054C3C; Mon, 27 Feb 2017 11:20:55 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RBKrHr003140 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 27 Feb 2017 06:20:54 -0500 Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 32F651138604; Mon, 27 Feb 2017 12:20:50 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 12:20:38 +0100 Message-Id: <1488194450-28056-13-git-send-email-armbru@redhat.com> In-Reply-To: <1488194450-28056-1-git-send-email-armbru@redhat.com> References: <1488194450-28056-1-git-send-email-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 27 Feb 2017 11:20:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/24] qobject: Propagate parse errors through qobject_from_json() 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: kwolf@redhat.com, "mdroth@linux.vnet.ibm.commdroth"@linux.vnet.ibm.com, pkrempa@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- block.c | 2 +- include/qapi/qmp/qjson.h | 5 +-- monitor.c | 2 +- qobject/qjson.c | 4 +-- tests/check-qjson.c | 62 +++++++++++++++++++---------------= ---- tests/test-visitor-serialization.c | 2 +- 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/block.c b/block.c index 3c36af5..aa6790c 100644 --- a/block.c +++ b/block.c @@ -1163,7 +1163,7 @@ static QDict *parse_json_filename(const char *filenam= e, Error **errp) ret =3D strstart(filename, "json:", &filename); assert(ret); =20 - options_obj =3D qobject_from_json(filename); + options_obj =3D qobject_from_json(filename, NULL); if (!options_obj) { error_setg(errp, "Could not parse the JSON options"); return NULL; diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h index 6fe42d0..8568f2d 100644 --- a/include/qapi/qmp/qjson.h +++ b/include/qapi/qmp/qjson.h @@ -17,8 +17,9 @@ #include "qapi/qmp/qobject.h" #include "qapi/qmp/qstring.h" =20 -QObject *qobject_from_json(const char *string); -QObject *qobject_from_jsonf(const char *string, ...) GCC_FMT_ATTR(1, 2); +QObject *qobject_from_json(const char *string, Error **errp); +QObject *qobject_from_jsonf(const char *string, ...) + GCC_FMT_ATTR(1, 2); QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp) GCC_FMT_ATTR(1, 0); =20 diff --git a/monitor.c b/monitor.c index 97b73ab..858bcda 100644 --- a/monitor.c +++ b/monitor.c @@ -950,7 +950,7 @@ EventInfoList *qmp_query_events(Error **errp) static void qmp_query_qmp_schema(QDict *qdict, QObject **ret_data, Error **errp) { - *ret_data =3D qobject_from_json(qmp_schema_json); + *ret_data =3D qobject_from_json(qmp_schema_json, NULL); } =20 /* diff --git a/qobject/qjson.c b/qobject/qjson.c index c98d6a7..b2f3bfe 100644 --- a/qobject/qjson.c +++ b/qobject/qjson.c @@ -50,9 +50,9 @@ QObject *qobject_from_jsonv(const char *string, va_list *= ap, Error **errp) return state.result; } =20 -QObject *qobject_from_json(const char *string) +QObject *qobject_from_json(const char *string, Error **errp) { - return qobject_from_jsonv(string, NULL, NULL); + return qobject_from_jsonv(string, NULL, errp); } =20 /* diff --git a/tests/check-qjson.c b/tests/check-qjson.c index e6d6935..aa63758 100644 --- a/tests/check-qjson.c +++ b/tests/check-qjson.c @@ -53,7 +53,7 @@ static void escaped_string(void) QObject *obj; QString *str; =20 - obj =3D qobject_from_json(test_cases[i].encoded); + obj =3D qobject_from_json(test_cases[i].encoded, NULL); str =3D qobject_to_qstring(obj); g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, test_cases[i].decode= d); @@ -85,7 +85,7 @@ static void simple_string(void) QObject *obj; QString *str; =20 - obj =3D qobject_from_json(test_cases[i].encoded); + obj =3D qobject_from_json(test_cases[i].encoded, NULL); str =3D qobject_to_qstring(obj); g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); @@ -116,7 +116,7 @@ static void single_quote_string(void) QObject *obj; QString *str; =20 - obj =3D qobject_from_json(test_cases[i].encoded); + obj =3D qobject_from_json(test_cases[i].encoded, NULL); str =3D qobject_to_qstring(obj); g_assert(str); g_assert(strcmp(qstring_get_str(str), test_cases[i].decoded) =3D= =3D 0); @@ -809,7 +809,7 @@ static void utf8_string(void) utf8_in =3D test_cases[i].utf8_in ?: test_cases[i].utf8_out; json_out =3D test_cases[i].json_out ?: test_cases[i].json_in; =20 - obj =3D qobject_from_json(json_in); + obj =3D qobject_from_json(json_in, NULL); if (utf8_out) { str =3D qobject_to_qstring(obj); g_assert(str); @@ -836,7 +836,7 @@ static void utf8_string(void) * FIXME Enable once these bugs have been fixed. */ if (0 && json_out !=3D json_in) { - obj =3D qobject_from_json(json_out); + obj =3D qobject_from_json(json_out, NULL); str =3D qobject_to_qstring(obj); g_assert(str); g_assert_cmpstr(qstring_get_str(str), =3D=3D, utf8_out); @@ -886,7 +886,7 @@ static void simple_number(void) for (i =3D 0; test_cases[i].encoded; i++) { QInt *qint; =20 - qint =3D qobject_to_qint(qobject_from_json(test_cases[i].encoded)); + qint =3D qobject_to_qint(qobject_from_json(test_cases[i].encoded, = NULL)); g_assert(qint); g_assert(qint_get_int(qint) =3D=3D test_cases[i].decoded); if (test_cases[i].skip =3D=3D 0) { @@ -920,7 +920,7 @@ static void float_number(void) QObject *obj; QFloat *qfloat; =20 - obj =3D qobject_from_json(test_cases[i].encoded); + obj =3D qobject_from_json(test_cases[i].encoded, NULL); qfloat =3D qobject_to_qfloat(obj); g_assert(qfloat); g_assert(qfloat_get_double(qfloat) =3D=3D test_cases[i].decoded); @@ -965,7 +965,7 @@ static void keyword_literal(void) QObject *null; QString *str; =20 - obj =3D qobject_from_json("true"); + obj =3D qobject_from_json("true", NULL); qbool =3D qobject_to_qbool(obj); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D true); @@ -976,7 +976,7 @@ static void keyword_literal(void) =20 QDECREF(qbool); =20 - obj =3D qobject_from_json("false"); + obj =3D qobject_from_json("false", NULL); qbool =3D qobject_to_qbool(obj); g_assert(qbool); g_assert(qbool_get_bool(qbool) =3D=3D false); @@ -998,7 +998,7 @@ static void keyword_literal(void) g_assert(qbool_get_bool(qbool) =3D=3D true); QDECREF(qbool); =20 - obj =3D qobject_from_json("null"); + obj =3D qobject_from_json("null", NULL); g_assert(obj !=3D NULL); g_assert(qobject_type(obj) =3D=3D QTYPE_QNULL); =20 @@ -1134,13 +1134,13 @@ static void simple_dict(void) QObject *obj; QString *str; =20 - obj =3D qobject_from_json(test_cases[i].encoded); + obj =3D qobject_from_json(test_cases[i].encoded, NULL); g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 - obj =3D qobject_from_json(qstring_get_str(str)); + obj =3D qobject_from_json(qstring_get_str(str), NULL); g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); qobject_decref(obj); QDECREF(str); @@ -1192,7 +1192,7 @@ static void large_dict(void) QObject *obj; =20 gen_test_json(gstr, 10, 100); - obj =3D qobject_from_json(gstr->str); + obj =3D qobject_from_json(gstr->str, NULL); g_assert(obj !=3D NULL); =20 qobject_decref(obj); @@ -1243,13 +1243,13 @@ static void simple_list(void) QObject *obj; QString *str; =20 - obj =3D qobject_from_json(test_cases[i].encoded); + obj =3D qobject_from_json(test_cases[i].encoded, NULL); g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 - obj =3D qobject_from_json(qstring_get_str(str)); + obj =3D qobject_from_json(qstring_get_str(str), NULL); g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); qobject_decref(obj); QDECREF(str); @@ -1305,13 +1305,13 @@ static void simple_whitespace(void) QObject *obj; QString *str; =20 - obj =3D qobject_from_json(test_cases[i].encoded); + obj =3D qobject_from_json(test_cases[i].encoded, NULL); g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); =20 str =3D qobject_to_json(obj); qobject_decref(obj); =20 - obj =3D qobject_from_json(qstring_get_str(str)); + obj =3D qobject_from_json(qstring_get_str(str), NULL); g_assert(compare_litqobj_to_qobj(&test_cases[i].decoded, obj) =3D= =3D 1); =20 qobject_decref(obj); @@ -1332,7 +1332,7 @@ static void simple_varargs(void) {}})), {}})); =20 - embedded_obj =3D qobject_from_json("[32, 42]"); + embedded_obj =3D qobject_from_json("[32, 42]", NULL); g_assert(embedded_obj !=3D NULL); =20 obj =3D qobject_from_jsonf("[%d, 2, %p]", 1, embedded_obj); @@ -1345,67 +1345,67 @@ static void empty_input(void) { const char *empty =3D ""; =20 - QObject *obj =3D qobject_from_json(empty); + QObject *obj =3D qobject_from_json(empty, NULL); g_assert(obj =3D=3D NULL); } =20 static void unterminated_string(void) { - QObject *obj =3D qobject_from_json("\"abc"); + QObject *obj =3D qobject_from_json("\"abc", NULL); g_assert(obj =3D=3D NULL); } =20 static void unterminated_sq_string(void) { - QObject *obj =3D qobject_from_json("'abc"); + QObject *obj =3D qobject_from_json("'abc", NULL); g_assert(obj =3D=3D NULL); } =20 static void unterminated_escape(void) { - QObject *obj =3D qobject_from_json("\"abc\\\""); + QObject *obj =3D qobject_from_json("\"abc\\\"", NULL); g_assert(obj =3D=3D NULL); } =20 static void unterminated_array(void) { - QObject *obj =3D qobject_from_json("[32"); + QObject *obj =3D qobject_from_json("[32", NULL); g_assert(obj =3D=3D NULL); } =20 static void unterminated_array_comma(void) { - QObject *obj =3D qobject_from_json("[32,"); + QObject *obj =3D qobject_from_json("[32,", NULL); g_assert(obj =3D=3D NULL); } =20 static void invalid_array_comma(void) { - QObject *obj =3D qobject_from_json("[32,}"); + QObject *obj =3D qobject_from_json("[32,}", NULL); g_assert(obj =3D=3D NULL); } =20 static void unterminated_dict(void) { - QObject *obj =3D qobject_from_json("{'abc':32"); + QObject *obj =3D qobject_from_json("{'abc':32", NULL); g_assert(obj =3D=3D NULL); } =20 static void unterminated_dict_comma(void) { - QObject *obj =3D qobject_from_json("{'abc':32,"); + QObject *obj =3D qobject_from_json("{'abc':32,", NULL); g_assert(obj =3D=3D NULL); } =20 static void invalid_dict_comma(void) { - QObject *obj =3D qobject_from_json("{'abc':32,}"); + QObject *obj =3D qobject_from_json("{'abc':32,}", NULL); g_assert(obj =3D=3D NULL); } =20 static void unterminated_literal(void) { - QObject *obj =3D qobject_from_json("nul"); + QObject *obj =3D qobject_from_json("nul", NULL); g_assert(obj =3D=3D NULL); } =20 @@ -1425,11 +1425,11 @@ static void limits_nesting(void) char buf[2 * (max_nesting + 1) + 1]; QObject *obj; =20 - obj =3D qobject_from_json(make_nest(buf, max_nesting)); + obj =3D qobject_from_json(make_nest(buf, max_nesting), NULL); g_assert(obj !=3D NULL); qobject_decref(obj); =20 - obj =3D qobject_from_json(make_nest(buf, max_nesting + 1)); + obj =3D qobject_from_json(make_nest(buf, max_nesting + 1), NULL); g_assert(obj =3D=3D NULL); } =20 diff --git a/tests/test-visitor-serialization.c b/tests/test-visitor-serial= ization.c index c7e64f0..37dff41 100644 --- a/tests/test-visitor-serialization.c +++ b/tests/test-visitor-serialization.c @@ -1037,7 +1037,7 @@ static void qmp_deserialize(void **native_out, void *= datap, visit_complete(d->qov, &d->obj); obj_orig =3D d->obj; output_json =3D qobject_to_json(obj_orig); - obj =3D qobject_from_json(qstring_get_str(output_json)); + obj =3D qobject_from_json(qstring_get_str(output_json), NULL); =20 QDECREF(output_json); d->qiv =3D qobject_input_visitor_new(obj); --=20 2.7.4