From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqgU-0007Rt-CH for qemu-devel@nongnu.org; Fri, 10 Aug 2012 10:59:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SzqgT-0000Yd-Aw for qemu-devel@nongnu.org; Fri, 10 Aug 2012 10:59:30 -0400 Received: from e06smtp18.uk.ibm.com ([195.75.94.114]:40753) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SzqgT-0000YF-2g for qemu-devel@nongnu.org; Fri, 10 Aug 2012 10:59:29 -0400 Received: from /spool/local by e06smtp18.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 10 Aug 2012 15:59:28 +0100 Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7AExJDY23068700 for ; Fri, 10 Aug 2012 14:59:19 GMT Received: from d06av04.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7AExOnD024005 for ; Fri, 10 Aug 2012 08:59:25 -0600 From: Stefan Hajnoczi Date: Fri, 10 Aug 2012 15:59:20 +0100 Message-Id: <1344610762-26945-2-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1344610762-26945-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1344610762-26945-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 1/3] vl.c: Exit QEMU early if no machine is found List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org, Dunrong Huang , Stefan Hajnoczi From: Dunrong Huang We check whether the variable machine is NULL or not before accessing it. If machine is NULL, exit QEMU with an error, this can avoids a segfault error. Markus Armbruster adds that the segfault can be reproduced as follows: $ qemu-system-xtensa -cpu help Signed-off-by: Dunrong Huang Reviewed-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi --- vl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vl.c b/vl.c index a4a520f..4871428 100644 --- a/vl.c +++ b/vl.c @@ -3204,6 +3204,11 @@ int main(int argc, char **argv, char **envp) } loc_set_none(); + if (machine == NULL) { + fprintf(stderr, "No machine found.\n"); + exit(1); + } + if (machine->hw_version) { qemu_set_version(machine->hw_version); } @@ -3246,11 +3251,6 @@ int main(int argc, char **argv, char **envp) data_dir = CONFIG_QEMU_DATADIR; } - if (machine == NULL) { - fprintf(stderr, "No machine found.\n"); - exit(1); - } - /* * Default to max_cpus = smp_cpus, in case the user doesn't * specify a max_cpus value. -- 1.7.10.4