kvmtool/run: set a default cmdline if not set

when starting with custom kernel and disk options, kernel_cmdline is
NULL; it results in a segfault while trying to look for a string
using `strstr`:

__strstr_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strstr-sse2-unaligned.S:40
0x00000000004056bf in kvm_cmd_run_init (argc=<optimized out>, argv=<optimized out>) at builtin-run.c:608
0x000000000040639d in kvm_cmd_run (argc=<optimized out>, argv=<optimized out>, prefix=<optimized out>) at builtin-run.c:659
0x0000000000412b8f in handle_command (command=0x62bbc0 <kvm_commands>, argc=5, argv=0x7fffffffe840) at kvm-cmd.c:84
0x00007ffff7211b45 in __libc_start_main (main=0x403540 <main>, argc=6, argv=0x7fffffffe838, init=<optimized out>, fini=<optimized out>,
  rtld_fini=<optimized out>, stack_end=0x7fffffffe828) at libc-start.c:287
0x0000000000403962 in _start ()

this patch suggests to set a minimal cmdline when kernel_cmdline is NULL

Fixes: 8a7163f3db ("kvmtool/run: append cfg.kernel_cmdline at the end of real_cmdline")
Signed-off-by: William Dauchy <william@gandi.net>
Signed-off-by: Will Deacon <will.deacon@arm.com>
This commit is contained in:
William Dauchy
2015-10-31 14:11:29 +01:00
committed by Will Deacon
parent 6d7eeb7a13
commit d583df25ed
+1 -1
View File
@@ -605,7 +605,7 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
if (kvm_setup_guest_init(kvm->cfg.custom_rootfs_name))
die("Failed to setup init for guest.");
}
} else if (!strstr(kvm->cfg.kernel_cmdline, "root=")) {
} else if (!kvm->cfg.kernel_cmdline || !strstr(kvm->cfg.kernel_cmdline, "root=")) {
strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
}