Commit 491150db37429b2f962f7bf13a10776d81049c81

Authored by aurel32
1 parent 15abc451

Fix crash caused by missing command line arguments

Signed-off-by: Stefan Weil <weil@mail.berlios.de>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6580 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 7 additions and 1 deletions
linux-user/main.c
... ... @@ -2301,6 +2301,8 @@ int main(int argc, char **argv, char **envp)
2301 2301 if (envlist_unsetenv(envlist, r) != 0)
2302 2302 usage();
2303 2303 } else if (!strcmp(r, "s")) {
  2304 + if (optind >= argc)
  2305 + break;
2304 2306 r = argv[optind++];
2305 2307 x86_stack_size = strtol(r, (char **)&r, 0);
2306 2308 if (x86_stack_size <= 0)
... ... @@ -2312,6 +2314,8 @@ int main(int argc, char **argv, char **envp)
2312 2314 } else if (!strcmp(r, "L")) {
2313 2315 interp_prefix = argv[optind++];
2314 2316 } else if (!strcmp(r, "p")) {
  2317 + if (optind >= argc)
  2318 + break;
2315 2319 qemu_host_page_size = atoi(argv[optind++]);
2316 2320 if (qemu_host_page_size == 0 ||
2317 2321 (qemu_host_page_size & (qemu_host_page_size - 1)) != 0) {
... ... @@ -2319,12 +2323,14 @@ int main(int argc, char **argv, char **envp)
2319 2323 exit(1);
2320 2324 }
2321 2325 } else if (!strcmp(r, "g")) {
  2326 + if (optind >= argc)
  2327 + break;
2322 2328 gdbstub_port = atoi(argv[optind++]);
2323 2329 } else if (!strcmp(r, "r")) {
2324 2330 qemu_uname_release = argv[optind++];
2325 2331 } else if (!strcmp(r, "cpu")) {
2326 2332 cpu_model = argv[optind++];
2327   - if (strcmp(cpu_model, "?") == 0) {
  2333 + if (cpu_model == NULL || strcmp(cpu_model, "?") == 0) {
2328 2334 /* XXX: implement xxx_cpu_list for targets that still miss it */
2329 2335 #if defined(cpu_list)
2330 2336 cpu_list(stdout, &fprintf);
... ...