From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qzw1C-0004Ei-MV for qemu-devel@nongnu.org; Sat, 03 Sep 2011 15:36:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qzw1B-00013X-Bk for qemu-devel@nongnu.org; Sat, 03 Sep 2011 15:36:42 -0400 Received: from mail-fx0-f45.google.com ([209.85.161.45]:50725) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qzw1B-00013F-6z for qemu-devel@nongnu.org; Sat, 03 Sep 2011 15:36:41 -0400 Received: by fxbb27 with SMTP id b27so2781680fxb.4 for ; Sat, 03 Sep 2011 12:36:40 -0700 (PDT) From: Sasha Levin Date: Sat, 3 Sep 2011 22:35:43 +0300 Message-Id: <1315078543-28522-1-git-send-email-levinsasha928@gmail.com> Subject: [Qemu-devel] [PATCH] pc_init: Fail on bad kernel List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Sasha Levin When providing QEMU with a bad '-kernel' parameter, such as a file which is not really a kernel, QEMU will attempt to allocate a huge amount of memory and fail either with "Failed to allocate memory: Cannot allocate memory" or a GLib error: "GLib-ERROR **: gmem.c:170: failed to allocate 18446744073709529965 bytes" This patch handles the case where the magic sig wasn't located in the provided kernel, and loading it as multiboot failed as well. Cc: Anthony Liguori Signed-off-by: Sasha Levin --- hw/pc.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/hw/pc.c b/hw/pc.c index 6b3662e..428440b 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -691,8 +691,14 @@ static void load_linux(void *fw_cfg, /* This looks like a multiboot kernel. If it is, let's stop treating it like a Linux kernel. */ if (load_multiboot(fw_cfg, f, kernel_filename, initrd_filename, - kernel_cmdline, kernel_size, header)) + kernel_cmdline, kernel_size, header)) { return; + } else { + fprintf(stderr, "qemu: could not load kernel '%s': %s\n", + kernel_filename, strerror(errno)); + exit(1); + } + protocol = 0; } -- 1.7.6.1