From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: Markus Armbruster <armbru@redhat.com>,
Marcel Apfelbaum <marcel.a@redhat.com>
Cc: mst@redhat.com, aik@ozlabs.ru, qemu-devel@nongnu.org,
lcapitulino@redhat.com, blauwirbel@gmail.com, jcmvbkbc@gmail.com,
edgar.iglesias@gmail.com, gxt@mprc.pku.edu.cn,
peter.chubb@nicta.com.au, proljc@gmail.com, agraf@suse.de,
scottwood@freescale.com, borntraeger@de.ibm.com,
hpoussin@reactos.org, aliguori@amazon.com, lersek@redhat.com,
chouteau@adacore.com, jan.kiszka@web.de, stefanha@redhat.com,
cornelia.huck@de.ibm.com, peter.crosthwaite@xilinx.com,
mark.langsdorf@calxeda.com, michael@walle.cc,
qemu-ppc@nongnu.org, pbonzini@redhat.com, afaerber@suse.de,
aurelien@aurel32.net
Subject: Re: [Qemu-devel] [PATCH 2/4] qapi: output visitor crashes qemu if it encounters a NULL value
Date: Thu, 15 May 2014 11:27:04 -0500 [thread overview]
Message-ID: <20140515162704.3192.88046@loki> (raw)
In-Reply-To: <87lhu3qaui.fsf@blackfin.pond.sub.org>
Quoting Markus Armbruster (2014-05-15 11:13:09)
> Marcel Apfelbaum <marcel.a@redhat.com> writes:
>
> > A NULL value is not added to visitor's stack, but there
> > is no check for that when the visitor tries to return
> > that value, leading to Qemu crash.
> >
> > Reviewed-by: Eric Blake <eblake@redhat.com>
> > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
> > ---
> > qapi/qmp-output-visitor.c | 5 +++++
> > 1 file changed, 5 insertions(+)
> >
> > diff --git a/qapi/qmp-output-visitor.c b/qapi/qmp-output-visitor.c
> > index 74a5684..0562f49 100644
> > --- a/qapi/qmp-output-visitor.c
> > +++ b/qapi/qmp-output-visitor.c
> > @@ -66,6 +66,11 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov)
> > static QObject *qmp_output_first(QmpOutputVisitor *qov)
> > {
> > QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
> > +
> > + if (!e) {
> > + return NULL;
> > + }
> > +
> > return e->value;
> > }
>
> Let's see how this thing works.
>
> The visitor's mutable state is a QStack, which is stack of (QObject,
> bool). We can ignore the bool; it's just for qmp_output_next_list().
>
> Visits start with an empty stack. See qmp_output_visitor_new().
>
> qmp_output_first() returns the object on the bottom of the stack.
> qmp_output_last() returns the object on the top of the stack.
>
> <rant>
> When you implement a stack with a double-ended queue, you're totally
> free to pick either end of the queue for top of stack. You're also free
> to name your functions accessing top and the bottom of the stack however
> you like. "Of course" the author picked queue end and function names
> for maximum confusion:
>
> static QObject *qmp_output_first(QmpOutputVisitor *qov)
> {
> QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
> return e->value;
> }
>
> static QObject *qmp_output_last(QmpOutputVisitor *qov)
> {
> QStackEntry *e = QTAILQ_FIRST(&qov->stack);
> return e->value;
> }
>
> I hate you.
> </rant>
>
> The result of the visit sits at the bottom of the stack. Empty stack,
> null result. See qmp_output_get_qobject().
>
> Visiting a scalar type creates the appropriate scalar QObject, and
> "adds" it. We'll find out what "adding" means shortly. See
> qmp_output_type_{int,bool,str,number}().
>
> Special case: null strings get converted to empty strings. See
> qmp_output_type_str().
>
> Starting a struct visit creates a QDict, adds it, and pushes it onto the
> stack. Ending it pops it from the stack. See
> qmp_output_{start,end}_struct().
>
> Starting a list visit creates a QList, adds it, and pushes it onto the
> stack. Ending it pops it from the stack. See
> qmp_output_{start,end}_list().
>
> Visiting a list member does nothing interesting; see
> qmp_output_next_list(). Aside: I suspect the GenericList traversal
> stuff now done in every next_list() method should be done in the visitor
> core instead.
>
> Now let's figure out what it means to "add" an object. This is
> qmp_output_add_obj().
>
> If the stack is still empty, the object is the root object, and it gets
> pushed.
>
> Else, if the object on top of the stack is a QDict, we're visiting a
> struct. Enter the object into the QDict.
>
> Else, if the object on top of the stack is a QList, we're visiting a
> list. Append the object to the QList.
>
> Else, the object on top of the stack must be scalar, and I think it must
> be the root object. We replace it by the object being added. WTF?
>
> This feels more complicated than it could be. Anyway, how could a null
> object end up at the bottom of the stack, so that qmp_output_first()
> chokes on it? I can't see that.
>
> If it can get added, then why can it be seen only by qmp_output_first(),
> but not by qmp_output_last() and qmp_output_pop()?
See my note above, the corner case we're hitting seems to be when there's
nothing in the stack at all: generating a QObject from an empty
QmpOutputVisitor.
This occurs with object_property_get_str skips visit_type_str if the
property-specific accessor returns NULL, but we still covert the
visitor to a QObject to pull the string out later.
next prev parent reply other threads:[~2014-05-15 16:27 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-07 14:42 [Qemu-devel] [Qemu-detvel] [PATCH 0/4] machine: QemuOpts per machine Marcel Apfelbaum
2014-05-07 14:42 ` [Qemu-devel] [PATCH 1/4] machine: conversion of QEMUMachineInitArgs to MachineState Marcel Apfelbaum
2014-05-12 16:00 ` Laszlo Ersek
2014-05-13 13:25 ` Cornelia Huck
2014-05-13 15:44 ` Michael S. Tsirkin
2014-05-13 17:34 ` Andreas Färber
2014-05-15 15:04 ` Markus Armbruster
2014-05-18 8:37 ` Marcel Apfelbaum
2014-05-16 14:39 ` Igor Mammedov
2014-05-16 18:33 ` Andreas Färber
2014-05-18 8:51 ` Marcel Apfelbaum
2014-05-16 16:20 ` Igor Mammedov
2014-05-16 18:38 ` Andreas Färber
2014-05-18 8:48 ` Marcel Apfelbaum
2014-05-07 14:42 ` [Qemu-devel] [PATCH 2/4] qapi: output visitor crashes qemu if it encounters a NULL value Marcel Apfelbaum
2014-05-13 17:36 ` Andreas Färber
2014-05-13 19:08 ` Eric Blake
2014-05-14 17:00 ` Andreas Färber
2014-05-14 17:29 ` Marcel Apfelbaum
2014-05-14 18:25 ` Luiz Capitulino
2014-05-14 19:51 ` Markus Armbruster
2014-05-14 20:38 ` Michael Roth
2014-05-18 8:42 ` Marcel Apfelbaum
2014-05-14 20:26 ` Andreas Färber
2014-05-15 16:13 ` Markus Armbruster
2014-05-15 16:27 ` Michael Roth [this message]
2014-05-15 17:19 ` Markus Armbruster
2014-05-15 17:55 ` Michael Roth
2014-05-07 14:42 ` [Qemu-devel] [PATCH 3/4] vl.c: do not set 'type' property in obj_set_property Marcel Apfelbaum
2014-05-13 17:39 ` Andreas Färber
2014-05-15 16:15 ` Markus Armbruster
2014-05-15 16:38 ` Andreas Färber
2014-05-15 17:13 ` Paolo Bonzini
2014-05-07 14:43 ` [Qemu-devel] [PATCH 4/4] hw/machine: qemu machine opts as properties to QemuMachineState Marcel Apfelbaum
2014-05-13 17:54 ` Andreas Färber
2014-05-13 13:13 ` [Qemu-devel] [Qemu-detvel] [PATCH 0/4] machine: QemuOpts per machine Marcel Apfelbaum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140515162704.3192.88046@loki \
--to=mdroth@linux.vnet.ibm.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aik@ozlabs.ru \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=aurelien@aurel32.net \
--cc=blauwirbel@gmail.com \
--cc=borntraeger@de.ibm.com \
--cc=chouteau@adacore.com \
--cc=cornelia.huck@de.ibm.com \
--cc=edgar.iglesias@gmail.com \
--cc=gxt@mprc.pku.edu.cn \
--cc=hpoussin@reactos.org \
--cc=jan.kiszka@web.de \
--cc=jcmvbkbc@gmail.com \
--cc=lcapitulino@redhat.com \
--cc=lersek@redhat.com \
--cc=marcel.a@redhat.com \
--cc=mark.langsdorf@calxeda.com \
--cc=michael@walle.cc \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.chubb@nicta.com.au \
--cc=peter.crosthwaite@xilinx.com \
--cc=proljc@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=scottwood@freescale.com \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).