hw/ppc/e500.c: Handle qemu_find_file() failure
PATCH 1/1 hw/ppc/e500.c: Handle qemu_find_file() failure
If qemu_find_file() doesn't find the BIOS it returns NULL; we were passing that unchecked through to load_elf(), which assumes a non-NULL pointer and may misbehave. In practice it fails with a weird message:
$ qemu-system-ppc -M ppce500 -display none -kernel nonesuch Bad address qemu-system-ppc: could not load firmware '(null)'
Handle the failure case better:
$ qemu-system-ppc -M ppce500 -display none -kernel nonesuch qemu-system-ppc: could not find firmware/kernel file 'nonesuch'
Spotted by Coverity (CID 1238954).
--- hw/ppc/e500.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/ppc/e500.c +4 -0
@@ -1047,6 +1047,10 @@ void ppce500_init(MachineState *machine) } filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , payload_name); +if (!filename) { +error_report ("could not find firmware/kernel file '%s'" , payload_name); +exit (1 ); + } payload_size = load_elf(filename, NULL, NULL, NULL, &bios_entry, &loadaddr, NULL, NULL,
Signature · 1 line
2.20.1
Quoted 26 lines · Peter Maydell
If
qemu_find_file()doesn't find the BIOS it returns NULL; we were passing that unchecked through toload_elf(), which assumes a non-NULL pointer and may misbehave. In practice it fails with a weird message:$ qemu-system-ppc -M ppce500 -display none -kernel nonesuch Bad address qemu-system-ppc: could not load firmware '(null)'Handle the failure case better:
$ qemu-system-ppc -M ppce500 -display none -kernel nonesuch qemu-system-ppc: could not find firmware/kernel file 'nonesuch'Spotted by Coverity (CID 1238954).
Signed-off-by Peter Maydell <[email protected]>--- hw/ppc/e500.c | 4 ++++ 1 file changed, 4 insertions(+)hw/ppc/e500.c +0
-0
hw/ppc/e500.c void ppce500_init(MachineState *machine) · line 1056
Quoted 10 lines
hw/ppc/e500.c +4
-0@@ -1047,6 +1047,10 @@ void ppce500_init(MachineState *machine) } filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , payload_name); +if (!filename) { +error_report ("could not find firmware/kernel file '%s'" , payload_name); +exit (1 ); + } payload_size = load_elf(filename, NULL, NULL, NULL, &bios_entry, &loadaddr, NULL, NULL,
David Gibson
AppliedQuoted 8 lines · Peter Maydell
If
qemu_find_file()doesn't find the BIOS it returns NULL; we were passing that unchecked through toload_elf(), which assumes a non-NULL pointer and may misbehave. In practice it fails with a weird message:$ qemu-system-ppc -M ppce500 -display none -kernel nonesuch Bad address qemu-system-ppc: could not load firmware '(null)'
Quoted 8 lines
Handle the failure case better:
$ qemu-system-ppc -M ppce500 -display none -kernel nonesuch qemu-system-ppc: could not find firmware/kernel file 'nonesuch'Spotted by Coverity (CID 1238954).
Signed-off-by Peter Maydell <[email protected]>
Applied to ppc-for-5.0, thanks.
Quoted 19 lines
--- hw/ppc/e500.c | 4 ++++ 1 file changed, 4 insertions(+)hw/ppc/e500.c +4
-0@@ -1047,6 +1047,10 @@ void ppce500_init(MachineState *machine) } filename =qemu_find_file (QEMU_FILE_TYPE_BIOS , payload_name); +if (!filename) { +error_report ("could not find firmware/kernel file '%s'" , payload_name); +exit (1 ); + } payload_size = load_elf(filename, NULL, NULL, NULL, &bios_entry, &loadaddr, NULL, NULL,
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson