From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUmqS-00041I-R3 for qemu-devel@nongnu.org; Wed, 04 Feb 2009 13:51:32 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUmqR-0003ze-9q for qemu-devel@nongnu.org; Wed, 04 Feb 2009 13:51:32 -0500 Received: from [199.232.76.173] (port=51622 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUmqR-0003zK-0L for qemu-devel@nongnu.org; Wed, 04 Feb 2009 13:51:31 -0500 Received: from moutng.kundenserver.de ([212.227.17.10]:56564) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LUmqQ-0001V2-7T for qemu-devel@nongnu.org; Wed, 04 Feb 2009 13:51:30 -0500 Received: from localhost ([127.0.0.1] ident=stefan) by flocke.weilnetz.de with esmtp (Exim 4.69) (envelope-from ) id 1LUmqO-0002Po-Ee for qemu-devel@nongnu.org; Wed, 04 Feb 2009 19:51:28 +0100 Message-ID: <4989E3B0.7060309@mail.berlios.de> Date: Wed, 04 Feb 2009 19:51:28 +0100 From: Stefan Weil MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------020902040508080505060209" Subject: [Qemu-devel] [Qemu] [PATCH] Fix crash caused by missing command line arguments Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers This is a multi-part message in MIME format. --------------020902040508080505060209 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Hi, some command line parameters for Qemu user mode take arguments. When Qemu is called with a parameter and the argument is missing, it gets a SIGSEGV crash. This patch tries to fix it for Linux user mode. Other user modes are expected to need similar fixes, but I cannot test them. Regards Stefan Weil --------------020902040508080505060209 Content-Type: text/x-diff; name="cmdline.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="cmdline.patch" Missing command line arguments caused a crash. Signed-off-by: Stefan Weil Index: trunk/linux-user/main.c =================================================================== --- trunk.orig/linux-user/main.c 2009-02-04 19:22:22.000000000 +0100 +++ trunk/linux-user/main.c 2009-02-04 19:44:03.000000000 +0100 @@ -2301,6 +2301,8 @@ if (envlist_unsetenv(envlist, r) != 0) usage(); } else if (!strcmp(r, "s")) { + if (optind >= argc) + break; r = argv[optind++]; x86_stack_size = strtol(r, (char **)&r, 0); if (x86_stack_size <= 0) @@ -2312,6 +2314,8 @@ } else if (!strcmp(r, "L")) { interp_prefix = argv[optind++]; } else if (!strcmp(r, "p")) { + if (optind >= argc) + break; qemu_host_page_size = atoi(argv[optind++]); if (qemu_host_page_size == 0 || (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) { @@ -2319,12 +2323,14 @@ exit(1); } } else if (!strcmp(r, "g")) { + if (optind >= argc) + break; gdbstub_port = atoi(argv[optind++]); } else if (!strcmp(r, "r")) { qemu_uname_release = argv[optind++]; } else if (!strcmp(r, "cpu")) { cpu_model = argv[optind++]; - if (strcmp(cpu_model, "?") == 0) { + if (cpu_model == NULL || strcmp(cpu_model, "?") == 0) { /* XXX: implement xxx_cpu_list for targets that still miss it */ #if defined(cpu_list) cpu_list(stdout, &fprintf); --------------020902040508080505060209--