Skip to contentSkip to conversation

Check for invalid initrd file

PATCH In review M. Mohan Kumar 2 participants 2 messages Mar 4, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check for invalid initrd file

From c5dca54f67ec6aac16c6c5e09958417b2b3ee5a1 Mon Sep 17 00:00:00 2001
From: M. Mohan Kumar <[email protected]>
Date: Thu, 4 Mar 2010 14:23:07 +0530
Subject: [PATCH] Check for invalid initrd file

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.

---
 hw/pc.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
hw/pc.c +6 -0
index 4f6a522..551c901 100644
@@ -669,6 +669,12 @@ static void load_linux(void *fw_cfg,
 	}
 
 	initrd_size = get_image_size(initrd_filename);
+	if (initrd_size < 0) {
+		fprintf(stderr, "qemu: initrd %s does not exist\n",
+							initrd_filename);
+		exit(1);
+	}
+
         initrd_addr = (initrd_max-initrd_size) & ~4095;
 
         initrd_data = qemu_malloc(initrd_size);
Signature · 6 lines
1.6.6.1


-- 
M. Mohan Kumar,
Linux Technology Center, IBM India
#1 lore raw
Quoted 18 lines · M. Mohan Kumar

From c5dca54f67ec6aac16c6c5e09958417b2b3ee5a1 Mon Sep 17 00:00:00 2001
From: M. Mohan Kumar <[email protected]>
Date: Thu, 4 Mar 2010 14:23:07 +0530
Subject: [PATCH] Check for invalid initrd file

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.

---
 hw/pc.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
hw/pc.c +0 -0
index 4f6a522..551c901 100644

hw/pc.c static void load_linux(void *fw_cfg, · line 675

Quoted 7 lines
hw/pc.c +4 -0
@@ -669,6 +669,12 @@ static void load_linux(void *fw_cfg,
 	}
 
 	initrd_size = get_image_size(initrd_filename);
+	if (initrd_size < 0) {
+		fprintf(stderr, "qemu: initrd %s does not exist\n",
+							initrd_filename);
+		exit(1);

Looks good...but you may want to check the formatting.

Also do we know for sure that the file not being there is the only reason for failure? How about making the error statement more generic like.. "Error reading %S"

Thanks,
JV

Quoted 5 lines
hw/pc.c +2 -0
+	}
+
         initrd_addr = (initrd_max-initrd_size) & ~4095;
 
         initrd_data = qemu_malloc(initrd_size);