Skip to contentSkip to conversation

hmp: Fix drive_add ... format=help crash

PATCH Superseded Markus Armbruster 3 participants 4 messages Apr 5, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hmp: Fix drive_add ... format=help crash

drive_new() returns null without setting an error when it provided help. add_init_drive() assumes null means failure, and crashes trying to report a null error.

Fixes c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25
---
 device-hotplug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
device-hotplug.c +1 -1
index 6090d5f1e9..6153259d71 100644
@@ -48,7 +48,7 @@ static DriveInfo *add_init_drive(const char *optstr)
 
     mc = MACHINE_GET_CLASS(current_machine);
     dinfo = drive_new(opts, mc->block_default_type, &err);
-    if (!dinfo) {
+    if (err) {
         error_report_err(err);
         qemu_opts_del(opts);
         return NULL;
Signature · 1 line
2.17.2
#1 lore raw

Am 05.04.2019 um 13:45 hat Markus Armbruster geschrieben:

Quoted 7 lines

drive_new() returns null without setting an error when it provided help. add_init_drive() assumes null means failure, and crashes trying to report a null error.

Fixes c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25

We should probably have a test case for this.

Kevin

#2 lore raw
Quoted 10 lines · * Kevin Wolf ([email protected]) wrote:

Am 05.04.2019 um 13:45 hat Markus Armbruster geschrieben:

Quoted 7 lines

drive_new() returns null without setting an error when it provided help. add_init_drive() assumes null means failure, and crashes trying to report a null error.

Fixes c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25

We should probably have a test case for this.

Perhaps just adding:

drive_add 0 format=help

to the hmp_cmds list in tests/test-hmp.c ?

Dave

Quoted 2 lines

Kevin

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw

Am 05.04.2019 um 18:11 hat Dr. David Alan Gilbert geschrieben:

Quoted 10 lines · * Kevin Wolf ([email protected]) wrote:
Quoted 9 lines

Am 05.04.2019 um 13:45 hat Markus Armbruster geschrieben:

Quoted 7 lines

drive_new() returns null without setting an error when it provided help. add_init_drive() assumes null means failure, and crashes trying to report a null error.

Fixes c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25
Quoted 7 lines
Quoted 1 line

We should probably have a test case for this.

Perhaps just adding:

drive_add 0 format=help

to the hmp_cmds list in tests/test-hmp.c ?

This would catch the crash, but not check the output. I think I'd prefer a qemu-iotests case where the output is checked.

Kevin