diff mbox

qdev-monitor: device_add crashes on non-device driver name, fix

Message ID 1385654544-1774-1-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Nov. 28, 2013, 4:02 p.m. UTC
From: Markus Armbruster <armbru@redhat.com>

Watch this:

    $ upstream-qemu -nodefaults -S -display none -monitor stdio
    QEMU 1.7.50 monitor - type 'help' for more information
    (qemu) device_add rng-egd
    /work/armbru/qemu/qdev-monitor.c:491:qdev_device_add: Object 0x2089b00 is not an instance of type device
    Aborted (core dumped)

Crashes because "rng-egd" exists, but isn't a subtype of TYPE_DEVICE.
Broken in commit 18b6dad.

Cc: qemu-stable@nongnu.org
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qdev-monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Andreas Färber Nov. 28, 2013, 4:11 p.m. UTC | #1
Am 28.11.2013 17:02, schrieb armbru@redhat.com:
> From: Markus Armbruster <armbru@redhat.com>
> 
> Watch this:
> 
>     $ upstream-qemu -nodefaults -S -display none -monitor stdio
>     QEMU 1.7.50 monitor - type 'help' for more information
>     (qemu) device_add rng-egd
>     /work/armbru/qemu/qdev-monitor.c:491:qdev_device_add: Object 0x2089b00 is not an instance of type device
>     Aborted (core dumped)
> 
> Crashes because "rng-egd" exists, but isn't a subtype of TYPE_DEVICE.
> Broken in commit 18b6dad.

Thanks for catching this!

> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  qdev-monitor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index dc37a43..90a0cea 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>          }
>      }
>  
> -    if (!oc) {
> +    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {

Are you sure we don't need !oc || !object_class_dynamic_cast(oc, ...)?

Regards,
Andreas

>          qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
>          return NULL;
>      }
>
Markus Armbruster Nov. 28, 2013, 4:19 p.m. UTC | #2
Andreas Färber <afaerber@suse.de> writes:

> Am 28.11.2013 17:02, schrieb armbru@redhat.com:
>> From: Markus Armbruster <armbru@redhat.com>
>> 
>> Watch this:
>> 
>>     $ upstream-qemu -nodefaults -S -display none -monitor stdio
>>     QEMU 1.7.50 monitor - type 'help' for more information
>>     (qemu) device_add rng-egd
>>     /work/armbru/qemu/qdev-monitor.c:491:qdev_device_add: Object
>> 0x2089b00 is not an instance of type device
>>     Aborted (core dumped)
>> 
>> Crashes because "rng-egd" exists, but isn't a subtype of TYPE_DEVICE.
>> Broken in commit 18b6dad.
>
> Thanks for catching this!
>
>> 
>> Cc: qemu-stable@nongnu.org
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  qdev-monitor.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/qdev-monitor.c b/qdev-monitor.c
>> index dc37a43..90a0cea 100644
>> --- a/qdev-monitor.c
>> +++ b/qdev-monitor.c
>> @@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>>          }
>>      }
>>  
>> -    if (!oc) {
>> +    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
>
> Are you sure we don't need !oc || !object_class_dynamic_cast(oc, ...)?

Yes.  First thing object_class_dynamic_cast() does is

    if (!class) {
        return NULL;
    }

Makes sense to me.

[...]
Markus Armbruster Dec. 18, 2013, 2:54 p.m. UTC | #3
Ping?

armbru@redhat.com writes:

> From: Markus Armbruster <armbru@redhat.com>
>
> Watch this:
>
>     $ upstream-qemu -nodefaults -S -display none -monitor stdio
>     QEMU 1.7.50 monitor - type 'help' for more information
>     (qemu) device_add rng-egd
>     /work/armbru/qemu/qdev-monitor.c:491:qdev_device_add: Object 0x2089b00 is not an instance of type device
>     Aborted (core dumped)
>
> Crashes because "rng-egd" exists, but isn't a subtype of TYPE_DEVICE.
> Broken in commit 18b6dad.
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  qdev-monitor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index dc37a43..90a0cea 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>          }
>      }
>  
> -    if (!oc) {
> +    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
>          qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
>          return NULL;
>      }
Andreas Färber Dec. 18, 2013, 3:50 p.m. UTC | #4
Am 18.12.2013 15:54, schrieb Markus Armbruster:
> Ping?

Already queued on qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next

Sorry, did the patch processing offline on a train. ;)

Thanks,
Andreas

> armbru@redhat.com writes:
> 
>> From: Markus Armbruster <armbru@redhat.com>
>>
>> Watch this:
>>
>>     $ upstream-qemu -nodefaults -S -display none -monitor stdio
>>     QEMU 1.7.50 monitor - type 'help' for more information
>>     (qemu) device_add rng-egd
>>     /work/armbru/qemu/qdev-monitor.c:491:qdev_device_add: Object 0x2089b00 is not an instance of type device
>>     Aborted (core dumped)
>>
>> Crashes because "rng-egd" exists, but isn't a subtype of TYPE_DEVICE.
>> Broken in commit 18b6dad.
>>
>> Cc: qemu-stable@nongnu.org
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  qdev-monitor.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/qdev-monitor.c b/qdev-monitor.c
>> index dc37a43..90a0cea 100644
>> --- a/qdev-monitor.c
>> +++ b/qdev-monitor.c
>> @@ -477,7 +477,7 @@ DeviceState *qdev_device_add(QemuOpts *opts)
>>          }
>>      }
>>  
>> -    if (!oc) {
>> +    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
>>          qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
>>          return NULL;
>>      }
>
Markus Armbruster Dec. 18, 2013, 5:06 p.m. UTC | #5
Andreas Färber <afaerber@suse.de> writes:

> Am 18.12.2013 15:54, schrieb Markus Armbruster:
>> Ping?
>
> Already queued on qom-next:
> https://github.com/afaerber/qemu-cpu/commits/qom-next
>
> Sorry, did the patch processing offline on a train. ;)

No problem & thanks!
diff mbox

Patch

diff --git a/qdev-monitor.c b/qdev-monitor.c
index dc37a43..90a0cea 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -477,7 +477,7 @@  DeviceState *qdev_device_add(QemuOpts *opts)
         }
     }
 
-    if (!oc) {
+    if (!object_class_dynamic_cast(oc, TYPE_DEVICE)) {
         qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "device type");
         return NULL;
     }