summaryrefslogtreecommitdiffstats
path: root/qobject
diff options
context:
space:
mode:
authorMarkus Armbruster2018-08-06 08:53:31 +0200
committerMarkus Armbruster2018-08-16 08:42:06 +0200
commit2d36e843042d2ef47f3bfc47a1a83401fdb07b84 (patch)
treecf0c271134caf76933cb959864404f46e6695341 /qobject
parenttest-qobject-input-visitor: Avoid format string ambiguity (diff)
downloadqemu-2d36e843042d2ef47f3bfc47a1a83401fdb07b84.tar.gz
qemu-2d36e843042d2ef47f3bfc47a1a83401fdb07b84.tar.xz
qemu-2d36e843042d2ef47f3bfc47a1a83401fdb07b84.zip
qobject: qobject_from_jsonv() is dangerous, hide it away
qobject_from_jsonv() takes ownership of %p arguments. On failure, we can't generally know whether we failed before or after %p, so ownership becomes indeterminate. To avoid leaks, callers passing %p must terminate on error, e.g. by passing &error_abort. Trap for the unwary; document and give the function internal linkage. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180806065344.7103-11-armbru@redhat.com>
Diffstat (limited to 'qobject')
-rw-r--r--qobject/qjson.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/qobject/qjson.c b/qobject/qjson.c
index 2e450231ff..ab4040f235 100644
--- a/qobject/qjson.c
+++ b/qobject/qjson.c
@@ -39,7 +39,18 @@ static void parse_json(JSONMessageParser *parser, GQueue *tokens)
s->result = json_parser_parse_err(tokens, s->ap, &s->err);
}
-QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp)
+/*
+ * Parse @string as JSON value.
+ * If @ap is non-null, interpolate %-escapes.
+ * Takes ownership of %p arguments.
+ * On success, return the JSON value.
+ * On failure, store an error through @errp and return NULL.
+ * Ownership of %p arguments becomes indeterminate then. To avoid
+ * leaks, callers passing %p must terminate on error, e.g. by passing
+ * &error_abort.
+ */
+static QObject *qobject_from_jsonv(const char *string, va_list *ap,
+ Error **errp)
{
JSONParsingState state = {};