qapi: Avoid output visitor crashing if it encounters a NULL value
authorMarcel Apfelbaum <marcel.a@redhat.com>
Mon, 26 May 2014 12:40:55 +0000 (15:40 +0300)
committerAndreas Färber <afaerber@suse.de>
Wed, 28 May 2014 15:36:04 +0000 (17:36 +0200)
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>
Acked-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
qapi/qmp-output-visitor.c

index 74a5684ed3d42a090763ba07b534c03ae57ecd4f..96b338463ed8f16e385921a1ca056cd4d9625cf4 100644 (file)
@@ -66,6 +66,12 @@ static QObject *qmp_output_pop(QmpOutputVisitor *qov)
 static QObject *qmp_output_first(QmpOutputVisitor *qov)
 {
     QStackEntry *e = QTAILQ_LAST(&qov->stack, QStack);
+
+    /* FIXME - find a better way to deal with NULL values */
+    if (!e) {
+        return NULL;
+    }
+
     return e->value;
 }