From f4e61d99c449a2c3c6c6038f7ed0d3fabfa1a616 Mon Sep 17 00:00:00 2001 From: Nageswara R Sastry Date: Mon, 28 Aug 2017 16:03:45 +0530 Subject: [PATCH] cpu: don't allow negative max_cpus When a negative max_cpus is not handled properly: -1 gives an inaccurate error message GLib-ERROR **: gmem.c:130: failed to allocate 18446744073709550568 bytes Trace/breakpoint trap -2 crashes QEMU (Abort and core dump) with older versions Added a check for validating the max_cpus to avoid any kind of unexpected errors or crashes. Signed-off-by: Nageswara R Sastry --- vl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vl.c b/vl.c index 8e247cc..aed3ae8 100644 --- a/vl.c +++ b/vl.c @@ -1245,6 +1245,11 @@ static void smp_parse(QemuOpts *opts) max_cpus = qemu_opt_get_number(opts, "maxcpus", cpus); + if (max_cpus < 0) { + error_report("Invalid max_cpus id: %d", max_cpus); + exit(1); + } + if (max_cpus < cpus) { error_report("maxcpus must be equal to or greater than smp"); exit(1); -- 2.9.3 (Apple Git-75)