Skip to contentSkip to conversation

hmp: Fix drive_add ... format=help crash

PATCH Applied Markus Armbruster 4 participants 4 messages Apr 8, 2019

lore
Share & tools
lore
#0 lore raw

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.

Fixes c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25

---
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
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;
tests/test-hmp.c +1 -0
index 8c49d2fdf1..54a01824dc 100644
@@ -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
Reviewed-by on v2 1/1
#1 lore raw
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 c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25

---
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
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;
tests/test-hmp.c +0 -0
index 8c49d2fdf1..54a01824dc 100644

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

Reviewed-by Tested-by on v2 1/1
#3 lore raw
In reply to Markus Armbruster
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 c4f26c9f37ce511e5fe629c21c180dc6eb7c5a25
Quoted 33 lines

---
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
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;
tests/test-hmp.c +1 -0
index 8c49d2fdf1..54a01824dc 100644
@@ -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",