From nobody Tue Nov 4 21:45:05 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530879406705992.3293661599948; Fri, 6 Jul 2018 05:16:46 -0700 (PDT) Received: from localhost ([::1]:57441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPfC-0008Dx-44 for importer@patchew.org; Fri, 06 Jul 2018 08:16:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59521) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fbPct-0006kP-Tf for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fbPcs-0005qQ-Pj for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55100 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 1fbPcs-0005qK-JK for qemu-devel@nongnu.org; Fri, 06 Jul 2018 08:14:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3CAFE407447D for ; Fri, 6 Jul 2018 12:14:14 +0000 (UTC) Received: from localhost (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1AB87C26; Fri, 6 Jul 2018 12:14:13 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2018 14:13:49 +0200 Message-Id: <20180706121354.2021-8-marcandre.lureau@redhat.com> In-Reply-To: <20180706121354.2021-1-marcandre.lureau@redhat.com> References: <20180706121354.2021-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 06 Jul 2018 12:14:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 06 Jul 2018 12:14:14 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' Content-Transfer-Encoding: quoted-printable 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 07/12] json-parser: always set an error if return NULL 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let's make json_parser_parse_err() suck less, and simplify caller error handling. * qga/main.c process_event() doesn't need further changes after previous cleanup. * qobject/json-parser.c json_parser_parse() Ignores the error. * qobject/qjson.c qobject_from_jsonv() via parse_json() - qobject_from_json() ~ block.c parse_json_filename() - removed workaround ~ block/rbd.c - abort (generated json - should never fail) ~ qapi/qobject-input-visitor.c - removed workaround ~ tests/check-qjson.c - abort, ok ~ tests/test-visitor-serialization.c - abort, ok - qobject_from_jsonf() Now dies in error_handle_fatal() instead of the assertion. Only used in tests, ok. - tests/test-qobject-input-visitor.c - tests/libqtest.c qmp_fd_sendv() Passes &error_abort, does nothing when qobject_from_jsonv() returns null. The fix makes this catch invalid JSON instead of silently ignoring it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- block.c | 5 ----- monitor.c | 4 ---- qapi/qobject-input-visitor.c | 5 ----- qobject/json-parser.c | 8 +++++++- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index ac8b3a3511..9046d66465 100644 --- a/block.c +++ b/block.c @@ -1478,11 +1478,6 @@ static QDict *parse_json_filename(const char *filena= me, Error **errp) =20 options_obj =3D qobject_from_json(filename, errp); if (!options_obj) { - /* Work around qobject_from_json() lossage TODO fix that */ - if (errp && !*errp) { - error_setg(errp, "Could not parse the JSON options"); - return NULL; - } error_prepend(errp, "Could not parse the JSON options: "); return NULL; } diff --git a/monitor.c b/monitor.c index ec40a80d81..a3efe96d1d 100644 --- a/monitor.c +++ b/monitor.c @@ -4112,10 +4112,6 @@ static void handle_qmp_command(JSONMessageParser *pa= rser, GQueue *tokens) QMPRequest *req_obj; =20 req =3D json_parser_parse_err(tokens, NULL, &err); - if (!req && !err) { - /* json_parser_parse_err() sucks: can fail without setting @err */ - error_setg(&err, QERR_JSON_PARSING); - } =20 qdict =3D qobject_to(QDict, req); if (qdict) { diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c index da57f4cc24..3e88b27f9e 100644 --- a/qapi/qobject-input-visitor.c +++ b/qapi/qobject-input-visitor.c @@ -725,11 +725,6 @@ Visitor *qobject_input_visitor_new_str(const char *str, if (is_json) { obj =3D qobject_from_json(str, errp); if (!obj) { - /* Work around qobject_from_json() lossage TODO fix that */ - if (errp && !*errp) { - error_setg(errp, "JSON parse error"); - return NULL; - } return NULL; } args =3D qobject_to(QDict, obj); diff --git a/qobject/json-parser.c b/qobject/json-parser.c index a5aa790d62..82c3167629 100644 --- a/qobject/json-parser.c +++ b/qobject/json-parser.c @@ -24,6 +24,7 @@ #include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-lexer.h" #include "qapi/qmp/json-streamer.h" +#include "qapi/qmp/qerror.h" =20 typedef struct JSONParserContext { @@ -591,7 +592,12 @@ QObject *json_parser_parse_err(GQueue *tokens, va_list= *ap, Error **errp) =20 result =3D parse_value(ctxt, ap); =20 - error_propagate(errp, ctxt->err); + if (!result && !ctxt->err) { + /* TODO: improve error reporting */ + error_setg(errp, QERR_JSON_PARSING); + } else { + error_propagate(errp, ctxt->err); + } =20 parser_context_free(ctxt); =20 --=20 2.18.0.rc1