From 0d433af617cd5beb98efe2834e9c9d8520f9b41b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 3 Mar 2018 17:38:14 -0500 Subject: [PATCH] qobject-input-visitor: Catch misuse of end_struct vs. end_list Backports commit 8b2e41d733850ec6a67a85743138e023cbb8921b from qemu --- qemu/qapi/qobject-input-visitor.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/qemu/qapi/qobject-input-visitor.c b/qemu/qapi/qobject-input-visitor.c index e475f023..672ecd9a 100644 --- a/qemu/qapi/qobject-input-visitor.c +++ b/qemu/qapi/qobject-input-visitor.c @@ -241,6 +241,15 @@ static void qobject_input_start_struct(Visitor *v, const char *name, void **obj, } } +static void qobject_input_end_struct(Visitor *v, void **obj) +{ + QObjectInputVisitor *qiv = to_qiv(v); + StackObject *tos = QSLIST_FIRST(&qiv->stack); + + assert(qobject_type(tos->obj) == QTYPE_QDICT && tos->h); + qobject_input_pop(v, obj); +} + static void qobject_input_start_list(Visitor *v, const char *name, GenericList **list, size_t size, Error **errp) { @@ -294,6 +303,15 @@ static void qobject_input_check_list(Visitor *v, Error **errp) } } +static void qobject_input_end_list(Visitor *v, void **obj) +{ + QObjectInputVisitor *qiv = to_qiv(v); + StackObject *tos = QSLIST_FIRST(&qiv->stack); + + assert(qobject_type(tos->obj) == QTYPE_QLIST && !tos->h); + qobject_input_pop(v, obj); +} + static void qobject_input_start_alternate(Visitor *v, const char *name, GenericAlternate **obj, size_t size, bool promote_int, Error **errp) @@ -491,12 +509,12 @@ static QObjectInputVisitor *qobject_input_visitor_base_new(QObject *obj) v->visitor.type = VISITOR_INPUT; v->visitor.start_struct = qobject_input_start_struct; v->visitor.check_struct = qobject_input_check_struct; - v->visitor.end_struct = qobject_input_pop; + v->visitor.end_struct = qobject_input_end_struct; v->visitor.start_alternate = qobject_input_start_alternate; v->visitor.start_list = qobject_input_start_list; v->visitor.next_list = qobject_input_next_list; v->visitor.check_list = qobject_input_check_list; - v->visitor.end_list = qobject_input_pop; + v->visitor.end_list = qobject_input_end_list; v->visitor.optional = qobject_input_optional; v->visitor.free = qobject_input_free;