Check for invalid initrd file
authorM. Mohan Kumar <mohan@in.ibm.com>
Mon, 12 Apr 2010 04:31:33 +0000 (10:01 +0530)
committerAurelien Jarno <aurelien@aurel32.net>
Sun, 18 Apr 2010 22:07:10 +0000 (00:07 +0200)
When qemu is invoked with an invalid initrd file, it crashes. Following
patch prints a error message and exits if an invalid initrd is
specified. Includes changes suggested by JV.

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
hw/pc.c

diff --git a/hw/pc.c b/hw/pc.c
index 69e597f3e202158a575f7d7ea91446185f2e2399..b797f218f79986ef31a6f698177e476cc66c95ee 100644 (file)
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -658,6 +658,12 @@ static void load_linux(void *fw_cfg,
        }
 
        initrd_size = get_image_size(initrd_filename);
+        if (initrd_size < 0) {
+            fprintf(stderr, "qemu: error reading initrd %s\n",
+                    initrd_filename);
+            exit(1);
+        }
+
         initrd_addr = (initrd_max-initrd_size) & ~4095;
 
         initrd_data = qemu_malloc(initrd_size);