From patchwork Wed Feb 22 22:40:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 6890 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 6CAA823EA8 for ; Wed, 22 Feb 2012 22:40:09 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 15BE4A187AE for ; Wed, 22 Feb 2012 22:40:08 +0000 (UTC) Received: by iabz7 with SMTP id z7so936085iab.11 for ; Wed, 22 Feb 2012 14:40:08 -0800 (PST) Received: from mr.google.com ([10.43.52.74]) by 10.43.52.74 with SMTP id vl10mr34717229icb.55.1329950408609 (num_hops = 1); Wed, 22 Feb 2012 14:40:08 -0800 (PST) MIME-Version: 1.0 Received: by 10.43.52.74 with SMTP id vl10mr27906172icb.55.1329950408555; Wed, 22 Feb 2012 14:40:08 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.11.10 with SMTP id r10csp147082ibr; Wed, 22 Feb 2012 14:40:07 -0800 (PST) Received: by 10.180.8.164 with SMTP id s4mr402395wia.6.1329950406994; Wed, 22 Feb 2012 14:40:06 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id s34si22614098weq.39.2012.02.22.14.40.06 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 22 Feb 2012 14:40:06 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1S0Kqu-0006LF-2o; Wed, 22 Feb 2012 22:40:00 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Anthony Liguori Subject: [PATCH] vl.c: Avoid segfault when started with no arguments Date: Wed, 22 Feb 2012 22:40:00 +0000 Message-Id: <1329950400-24354-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQnBSfuhftSebEeCXtHrQOmTfxuqG/gH58irl+23/PqgFmVgrT3obvxvJGEMW4SVhAcqGQf0 Fix a bug (introduced in commit a0abe47) where a command line which specified no machine arguments (either explicitly or implicitly via -kernel &co) would result in a segfault because of a NULL pointer returned from qemu_opts_find(qemu_find_opts("machine"), 0). Signed-off-by: Peter Maydell --- Oops, sorry about that... I must have tested the case where you do pass -kernel &co but forgot to test the case where you don't. vl.c | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-) diff --git a/vl.c b/vl.c index 7a8cc08..8375576 100644 --- a/vl.c +++ b/vl.c @@ -2188,7 +2188,7 @@ int main(int argc, char **argv, char **envp) DisplayState *ds; DisplayChangeListener *dcl; int cyls, heads, secs, translation; - QemuOpts *hda_opts = NULL, *opts; + QemuOpts *hda_opts = NULL, *opts, *machine_opts; QemuOptsList *olist; int optind; const char *optarg; @@ -3247,12 +3247,15 @@ int main(int argc, char **argv, char **envp) exit(1); } - kernel_filename = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"), - 0), "kernel"); - initrd_filename = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"), - 0), "initrd"); - kernel_cmdline = qemu_opt_get(qemu_opts_find(qemu_find_opts("machine"), - 0), "append"); + machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0); + if (machine_opts) { + kernel_filename = qemu_opt_get(machine_opts, "kernel"); + initrd_filename = qemu_opt_get(machine_opts, "initrd"); + kernel_cmdline = qemu_opt_get(machine_opts, "append"); + } else { + kernel_filename = initrd_filename = kernel_cmdline = NULL; + } + if (!kernel_cmdline) { kernel_cmdline = ""; }