Skip to contentSkip to conversation

Fix crash caused by missing command line arguments

PATCH Applied Stefan Weil 2 participants 2 messages Feb 4, 2009 – Feb 9, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix crash caused by missing command line arguments

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

Missing command line arguments caused a crash.

linux-user/main.c +7 -1
Index: trunk/linux-user/main.c
===================================================================
@@ -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);
#1 lore raw
Quoted 6 lines · Stefan Weil

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.

Quoted 7 lines

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.

Quoted 42 lines

Missing command line arguments caused a crash.

Index: trunk/linux-user/main.c
===================================================================

linux-user/main.c +7 -1
@@ -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);
Signature · 2 lines
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net