The usage of error_prepend() in some of the error contexts of
xen_console_device_create() is incorrect, as `errp` hasn't been initialized.
This leads to the following segmentation fault on error paths resulting from
xenstore reads:
Program terminated with signal SIGSEGV, Segmentation fault.
Address not mapped to object.
fmt=0x15c4dfeade42 "failed to read console device type: ",
ap=0x15cd0165ab50)
at ../qemu-xen-dir-remote/util/error.c:142
142 g_string_append(newmsg, (*errp)->msg);
[...]
(gdb) bt
(errp=0x15cd0165ae10, fmt=0x15c4dfeade42 "failed to read console device
type: ", ap=0x15cd0165ab50) at ../qemu-xen-dir-remote/util/error.c:142
(errp=0x15cd0165ae10, fmt=0x15c4dfeade42 "failed to read console device
type: ")
at ../qemu-xen-dir-remote/util/error.c:152
(backend=0x43944de00660, opts=0x43944c929000, errp=0x15cd0165ae10)
at ../qemu-xen-dir-remote/hw/char/xen_console.c:555
Replace usages of error_prepend() with error_setg() where appropriate.
Fixes: 9b7737469080 ('hw/xen: update Xen console to XenDevice model')
Signed-off-by: Roger Pau Monné <[email protected]>
---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony PERARD <[email protected]>
Cc: Paul Durrant <[email protected]>
Cc: "Edgar E. Iglesias" <[email protected]>
Cc: "Marc-André Lureau" <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: [email protected]
---
hw/char/xen_console.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c
index ef0c2912efa1..af706c7ef440 100644
--- a/hw/char/xen_console.c
+++ b/hw/char/xen_console.c
@@ -551,7 +551,7 @@ static void xen_console_device_create(XenBackendInstance
*backend,
}
if (xs_node_scanf(xsh, XBT_NULL, fe, "type", errp, "%ms", &type) != 1) {
- error_prepend(errp, "failed to read console device type: ");
+ error_setg(errp, "failed to read console device type: ");
goto fail;
}
@@ -582,7 +582,7 @@ static void xen_console_device_create(XenBackendInstance
*backend,
} else if (number) {
cd = serial_hd(number);
if (!cd) {
- error_prepend(errp, "console: No serial device #%ld found: ",
+ error_setg(errp, "console: No serial device #%ld found: ",
number);
goto fail;
}
--
2.46.0