[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 09/23] qobject: qobject_from_jsonv() is dangerous
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PATCH v2 09/23] qobject: qobject_from_jsonv() is dangerous, hide it away |
Date: |
Fri, 27 Jul 2018 17:13:45 +0200 |
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 <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
---
include/qapi/qmp/qjson.h | 2 --
qobject/qjson.c | 13 ++++++++++++-
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/include/qapi/qmp/qjson.h b/include/qapi/qmp/qjson.h
index dce78583dc..5ebbe5a118 100644
--- a/include/qapi/qmp/qjson.h
+++ b/include/qapi/qmp/qjson.h
@@ -15,8 +15,6 @@
#define QJSON_H
QObject *qobject_from_json(const char *string, Error **errp);
-QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp)
- GCC_FMT_ATTR(1, 0);
QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap)
GCC_FMT_ATTR(1, 0);
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 = {};
--
2.17.1
- [Qemu-devel] [PATCH v2 00/23] tests: Compile-time format string checking for libqtest.h, Markus Armbruster, 2018/07/27
- [Qemu-devel] [PATCH v2 08/23] test-qobject-input-visitor: Avoid format string ambiguity, Markus Armbruster, 2018/07/27
- [Qemu-devel] [PATCH v2 03/23] libqtest: Clean up how we read device_del messages, Markus Armbruster, 2018/07/27
- [Qemu-devel] [PATCH v2 06/23] qobject: New qobject_from_vjsonf_nofail(), qdict_from_vjsonf_nofail(), Markus Armbruster, 2018/07/27
- [Qemu-devel] [PATCH v2 09/23] qobject: qobject_from_jsonv() is dangerous, hide it away,
Markus Armbruster <=
- [Qemu-devel] [PATCH v2 22/23] libqtest: Replace qtest_startf() by qtest_initf(), Markus Armbruster, 2018/07/27
- [Qemu-devel] [PATCH v2 19/23] migration-test: Clean up string interpolation into QMP, part 3, Markus Armbruster, 2018/07/27
- [Qemu-devel] [PATCH v2 21/23] libqtest: Remove qtest_qmp_discard_response() & friends, Markus Armbruster, 2018/07/27