diff mbox

[v2,1/2] pc_sysfw: Check for qemu_find_file() failure

Message ID 87a9tsh8ui.fsf_-_@blackfin.pond.sub.org
State New
Headers show

Commit Message

Markus Armbruster Dec. 5, 2012, 2:28 p.m. UTC
pc_fw_add_pflash_drv() ignores qemu_find_file() failure, and happily
creates a drive without a medium.

When pc_system_flash_init() asks for its size, bdrv_getlength() fails
with -ENOMEDIUM, which isn't checked either.  It fails relatively
cleanly only because -ENOMEDIUM isn't a multiple of 4096:

    $ qemu-system-x86_64 -S -vnc :0 -bios nonexistant
    qemu: PC system firmware (pflash) must be a multiple of 0x1000
    [Exit 1 ]

Fix by handling the qemu_find_file() failure.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
v2: Don't report errno, because that can produce misleading error
messages.  For instance, when "seabios/out/bios.bin" is unreadable, we
fall back to $data_dir/seabios/out/bios.bin, which doesn't exist, and
then report "seabios/out/bios.bin: No such file or directory".  No other
caller reports errno.

 hw/pc_sysfw.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Stefan Hajnoczi Dec. 19, 2012, 9:29 a.m. UTC | #1
On Wed, Dec 05, 2012 at 03:28:05PM +0100, Markus Armbruster wrote:
> pc_fw_add_pflash_drv() ignores qemu_find_file() failure, and happily
> creates a drive without a medium.
> 
> When pc_system_flash_init() asks for its size, bdrv_getlength() fails
> with -ENOMEDIUM, which isn't checked either.  It fails relatively
> cleanly only because -ENOMEDIUM isn't a multiple of 4096:
> 
>     $ qemu-system-x86_64 -S -vnc :0 -bios nonexistant
>     qemu: PC system firmware (pflash) must be a multiple of 0x1000
>     [Exit 1 ]
> 
> Fix by handling the qemu_find_file() failure.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> v2: Don't report errno, because that can produce misleading error
> messages.  For instance, when "seabios/out/bios.bin" is unreadable, we
> fall back to $data_dir/seabios/out/bios.bin, which doesn't exist, and
> then report "seabios/out/bios.bin: No such file or directory".  No other
> caller reports errno.
> 
>  hw/pc_sysfw.c | 4 ++++
>  1 file changed, 4 insertions(+)

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan
diff mbox

Patch

diff --git a/hw/pc_sysfw.c b/hw/pc_sysfw.c
index 9d7c5f4..a161e7b 100644
--- a/hw/pc_sysfw.c
+++ b/hw/pc_sysfw.c
@@ -84,6 +84,10 @@  static void pc_fw_add_pflash_drv(void)
         bios_name = BIOS_FILENAME;
     }
     filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
+    if (!filename) {
+        error_report("Can't open BIOS image %s", bios_name);
+        exit(1);
+    }
 
     opts = drive_add(IF_PFLASH, -1, filename, "readonly=on");