* [Qemu-devel] [Qemu] [PATCH] Fix crash caused by missing command line arguments
@ 2009-02-04 18:51 Stefan Weil
2009-02-09 19:02 ` Aurelien Jarno
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil @ 2009-02-04 18:51 UTC (permalink / raw)
To: QEMU Developers
[-- Attachment #1: Type: text/plain, Size: 309 bytes --]
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
[-- Attachment #2: cmdline.patch --]
[-- Type: text/x-diff, Size: 1657 bytes --]
Missing command line arguments caused a crash.
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
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);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [Qemu] [PATCH] Fix crash caused by missing command line arguments
2009-02-04 18:51 [Qemu-devel] [Qemu] [PATCH] Fix crash caused by missing command line arguments Stefan Weil
@ 2009-02-09 19:02 ` Aurelien Jarno
0 siblings, 0 replies; 2+ messages in thread
From: Aurelien Jarno @ 2009-02-09 19:02 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-devel
On Wed, Feb 04, 2009 at 07:51:28PM +0100, Stefan Weil wrote:
> 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
>
>
Thanks, applied.
> Missing command line arguments caused a crash.
>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
>
> 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);
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-02-09 19:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-04 18:51 [Qemu-devel] [Qemu] [PATCH] Fix crash caused by missing command line arguments Stefan Weil
2009-02-09 19:02 ` Aurelien Jarno
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.