hmp: Fix drive_add ... format=help crash
PATCH v2 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.
---
v2: Make tests/test-hmp.c cover the bug
device-hotplug.c | 2 +- tests/test-hmp.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
device-hotplug.c +1 -1
@@ -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 ;
tests/test-hmp.c +1 -0
@@ -31,6 +31,7 @@ static const char *hmp_cmds[] = {"cpu 0" ,"device_add ?" ,"device_add usb-mouse,id=mouse1" , +"drive_add ignored format=help" ,"mouse_button 7" ,"mouse_move 10 10" , "mouse_button 0",
Signature · 1 line
2.17.2
Quoted 32 lines · * Markus Armbruster ([email protected]) wrote:
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 c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25Signed-off-by Markus Armbruster <[email protected]>---
v2: Maketests/test-hmp.ccover the bugdevice-hotplug.c | 2 +- tests/test-hmp.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)device-hotplug.c +1
-1@@ -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 ;tests/test-hmp.c +0
-0
tests/test-hmp.c static const char *hmp_cmds[] = { · line 34
Quoted 4 lines
tests/test-hmp.c +1
-0@@ -31,6 +31,7 @@ static const char *hmp_cmds[] = {"cpu 0" ,"device_add ?" ,"device_add usb-mouse,id=mouse1" , + "drive_add ignored format=help",
Quoted 6 lines
tests/test-hmp.c +0
-0"mouse_button 7" ,"mouse_move 10 10" , "mouse_button 0",Signature · 1 line
2.17.2
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Kevin Wolf
AppliedAm 08.04.2019 um 17:30 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 c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25Signed-off-by Markus Armbruster <[email protected]>
Thanks, applied to the block branch.
Kevin
Quoted 7 lines · Markus Armbruster
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 c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25Signed-off-by Markus Armbruster <[email protected]>
Quoted 33 lines
---
v2: Maketests/test-hmp.ccover the bugdevice-hotplug.c | 2 +- tests/test-hmp.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)device-hotplug.c +1
-1@@ -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 ;tests/test-hmp.c +1
-0@@ -31,6 +31,7 @@ static const char *hmp_cmds[] = {"cpu 0" ,"device_add ?" ,"device_add usb-mouse,id=mouse1" , +"drive_add ignored format=help" ,"mouse_button 7" ,"mouse_move 10 10" , "mouse_button 0",