Signed-off-by: liguang lig.fnst@cn.fujitsu.com --- hw/pc.c | 14 +++++++++++--- 1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/hw/pc.c b/hw/pc.c index 01d00f6..0ccd775 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -652,12 +652,20 @@ static void load_linux(void *fw_cfg, char *vmode;
/* Align to 16 bytes as a paranoia measure */ - cmdline_size = (strlen(kernel_cmdline)+16) & ~15; + cmdline_size = (strlen(kernel_cmdline)+16) & ~0xf;
/* load the kernel header */ f = fopen(kernel_filename, "rb"); - if (!f || !(kernel_size = get_file_size(f)) || - fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) != + if (!f) { + fprintf(stderr, "can't open kernel image file\n"); + exit(1); + } + kernel_size = get_file_size(f); + if (kernel_size <= 0) { + fprintf(stderr, "can't get size of kernel image file\n"); + exit(1); + } + if (fread(header, 1, MIN(ARRAY_SIZE(header), kernel_size), f) != MIN(ARRAY_SIZE(header), kernel_size)) { fprintf(stderr, "qemu: could not load kernel '%s': %s\n", kernel_filename, strerror(errno));