qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Check for invalid initrd file
@ 2010-03-04  9:02 M. Mohan Kumar
  2010-03-04 18:16 ` jvrao
  0 siblings, 1 reply; 3+ messages in thread
From: M. Mohan Kumar @ 2010-03-04  9:02 UTC (permalink / raw)
  To: qemu-devel

From c5dca54f67ec6aac16c6c5e09958417b2b3ee5a1 Mon Sep 17 00:00:00 2001
From: M. Mohan Kumar <mohan@in.ibm.com>
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.

Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
---
 hw/pc.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index 4f6a522..551c901 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -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);
-- 
1.6.6.1


-- 
M. Mohan Kumar,
Linux Technology Center, IBM India

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] Check for invalid initrd file
  2010-03-04  9:02 M. Mohan Kumar
@ 2010-03-04 18:16 ` jvrao
  0 siblings, 0 replies; 3+ messages in thread
From: jvrao @ 2010-03-04 18:16 UTC (permalink / raw)
  To: M. Mohan Kumar; +Cc: qemu-devel

M. Mohan Kumar wrote:
> From c5dca54f67ec6aac16c6c5e09958417b2b3ee5a1 Mon Sep 17 00:00:00 2001
> From: M. Mohan Kumar <mohan@in.ibm.com>
> 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.
> 
> Signed-off-by: M. Mohan Kumar <mohan@in.ibm.com>
> ---
>  hw/pc.c |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/pc.c b/hw/pc.c
> index 4f6a522..551c901 100644
> --- a/hw/pc.c
> +++ b/hw/pc.c
> @@ -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

> +	}
> +
>          initrd_addr = (initrd_max-initrd_size) & ~4095;
>  
>          initrd_data = qemu_malloc(initrd_size);

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH] Check for invalid initrd file
@ 2010-04-12  4:31 M. Mohan Kumar
  0 siblings, 0 replies; 3+ messages in thread
From: M. Mohan Kumar @ 2010-04-12  4:31 UTC (permalink / raw)
  To: qemu-devel, jvrao

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>
---
 hw/pc.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/pc.c b/hw/pc.c
index ba14df0..99649ba 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -657,6 +657,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);
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-12  4:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-12  4:31 [Qemu-devel] [PATCH] Check for invalid initrd file M. Mohan Kumar
  -- strict thread matches above, loose matches on Subject: below --
2010-03-04  9:02 M. Mohan Kumar
2010-03-04 18:16 ` jvrao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).