>From 1099b09bcdde9a80c5b0383cd063af6ad9ca18e5 Mon Sep 17 00:00:00 2001 From: Zhang Xiantao <[EMAIL PROTECTED]> Date: Thu, 3 Jan 2008 17:22:36 +0800 Subject: [PATCH] kvm: qemu : Add check for guest firmware.
Add the existence check before reading the image.
Signed-off-by: Zhang Xiantao <[EMAIL PROTECTED]>
---
qemu/hw/ipf.c | 3 ++-
qemu/target-ia64/firmware.c | 18 +++++++++++++-----
qemu/target-ia64/firmware.h | 2 +-
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/qemu/hw/ipf.c b/qemu/hw/ipf.c
index d8e1184..eb4cac3 100644
--- a/qemu/hw/ipf.c
+++ b/qemu/hw/ipf.c
@@ -419,7 +419,8 @@ static void ipf_init1(ram_addr_t ram_size, int
vga_ram_size,
image = read_image(buf, &image_size );
if (NULL == image || !image_size) {
fprintf(stderr, "Error when reading Guest
Firmware!\n");
- return ;
+ fprintf(stderr, "Please check Guest firmware at
%s\n", buf);
+ exit(1);
}
fw_image_start = fw_start + GFW_SIZE - image_size;
diff --git a/qemu/target-ia64/firmware.c b/qemu/target-ia64/firmware.c
index 51650c8..edabd70 100644
--- a/qemu/target-ia64/firmware.c
+++ b/qemu/target-ia64/firmware.c
@@ -22,6 +22,10 @@
#include <string.h>
#include <stdlib.h>
#include <zlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#include "cpu.h"
#include "firmware.h"
@@ -514,16 +518,17 @@ char *read_image(const char *filename, unsigned
long *size)
if ( (filename == NULL) || (size == NULL) )
return NULL;
- if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
+ kernel_fd = open(filename, O_RDONLY);
+ if (kernel_fd < 0)
{
- Hob_Output("Could not open kernel image");
- goto out;
+ Hob_Output("Could not open kernel image\n");
+ goto out_1;
}
if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
{
- Hob_Output("Could not allocate decompression state for state
file");
- goto out;
+ Hob_Output("Could not allocate decompression state for state
file\n");
+ goto out_1;
}
*size = 0;
@@ -577,6 +582,9 @@ char *read_image(const char *filename, unsigned long
*size)
else if ( kernel_fd >= 0 )
close(kernel_fd);
return image;
+
+out_1:
+ return NULL;
}
/*
diff --git a/qemu/target-ia64/firmware.h b/qemu/target-ia64/firmware.h
index 1c4e534..dde8b2d 100644
--- a/qemu/target-ia64/firmware.h
+++ b/qemu/target-ia64/firmware.h
@@ -36,7 +36,7 @@
#define HOB_OFFSET (GFW_HOB_START-GFW_START)
#define Hob_Output(s) \
- fprintf(stderr, strcat("HOB:",s))
+ fprintf(stderr, s)
extern int kvm_ia64_build_hob(unsigned long memsize,
unsigned long vcpus, uint8_t* fw_start);
--
1.5.2
0002-kvm-qemu-Add-check-for-guest-firmware.patch
Description: 0002-kvm-qemu-Add-check-for-guest-firmware.patch
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ kvm-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/kvm-devel
