Patchwork [v2,5/6] load_linux: report open kernel file & its size error

login
register
mail settings
Submitter liguang
Date Feb. 22, 2013, 4:15 a.m.
Message ID <1361506533-28463-6-git-send-email-lig.fnst@cn.fujitsu.com>
Download mbox | patch
Permalink /patch/222463/
State New
Headers show

Comments

liguang - Feb. 22, 2013, 4:15 a.m.
Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
---
 hw/pc.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

Patch

diff --git a/hw/pc.c b/hw/pc.c
index fd3a68c..30b3262 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -652,12 +652,22 @@  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 = QEMU_ALIGN_UP(strlen(kernel_cmdline), 16);
 
     /* 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: %s\n",
+                strerror(errno));
+        exit(1);
+    }
+    kernel_size = get_file_size(f);
+    if (kernel_size <= 0) {
+        fprintf(stderr, "can't get size of kernel image file: %s\n",
+                strerror(errno));
+        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));