qmp: object-add: Validate class before creating object
commitc3481247e58ff3f13337ce0a262b058799bd156c
authorEduardo Habkost <ehabkost@redhat.com>
Wed, 16 Apr 2014 17:39:38 +0000 (16 14:39 -0300)
committerLuiz Capitulino <lcapitulino@redhat.com>
Fri, 25 Apr 2014 15:08:34 +0000 (25 11:08 -0400)
treef23c7e40beebc16fd106c46f9b437e82d873d8c0
parent2da1b3abbccd267f09ebda7ba604fbbb0220f406
qmp: object-add: Validate class before creating object

Currently it is very easy to crash QEMU by issuing an object-add command
using an abstract class or a class that doesn't support
TYPE_USER_CREATABLE as parameter.

Example: with the following QMP command:

    (QEMU) object-add qom-type=cpu id=foo

QEMU aborts at:

    ERROR:qom/object.c:335:object_initialize_with_type: assertion failed: (type->abstract == false)

This patch moves the check for TYPE_USER_CREATABLE before object_new(),
and adds a check to prevent the code from trying to instantiate abstract
classes.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
Tested-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
qmp.c