[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 07/11] cpu: Fix crash with empty -cpu option
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PULL 07/11] cpu: Fix crash with empty -cpu option |
Date: |
Thu, 25 Apr 2019 14:56:55 -0300 |
Fix the following crash:
$ qemu-system-x86_64 -cpu ''
qemu-system-x86_64: qom/cpu.c:291: cpu_class_by_name: \
Assertion `cpu_model && cc->class_by_name' failed.
Regression test script included.
Fixes: 99193d8f2ef5 ("cpu: drop unnecessary NULL check and
cpu_common_class_by_name()")
Signed-off-by: Eduardo Habkost <address@hidden>
Message-Id: <address@hidden>
Reviewed-by: Stefano Garzarella <address@hidden>
Tested-by: Stefano Garzarella <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
---
exec.c | 4 ++++
tests/acceptance/empty_cpu_model.py | 19 +++++++++++++++++++
2 files changed, 23 insertions(+)
create mode 100644 tests/acceptance/empty_cpu_model.py
diff --git a/exec.c b/exec.c
index 08f6cafcbc..f7f3cdbf4a 100644
--- a/exec.c
+++ b/exec.c
@@ -991,6 +991,10 @@ const char *parse_cpu_option(const char *cpu_option)
const char *cpu_type;
model_pieces = g_strsplit(cpu_option, ",", 2);
+ if (!model_pieces[0]) {
+ error_report("-cpu option cannot be empty");
+ exit(1);
+ }
oc = cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]);
if (oc == NULL) {
diff --git a/tests/acceptance/empty_cpu_model.py
b/tests/acceptance/empty_cpu_model.py
new file mode 100644
index 0000000000..3f4f663582
--- /dev/null
+++ b/tests/acceptance/empty_cpu_model.py
@@ -0,0 +1,19 @@
+# Check for crash when using empty -cpu option
+#
+# Copyright (c) 2019 Red Hat, Inc.
+#
+# Author:
+# Eduardo Habkost <address@hidden>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later. See the COPYING file in the top-level directory.
+import subprocess
+from avocado_qemu import Test
+
+class EmptyCPUModel(Test):
+ def test(self):
+ cmd = [self.qemu_bin, '-S', '-display', 'none', '-machine', 'none',
'-cpu', '']
+ r = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ self.assertEquals(r.returncode, 1, "QEMU exit code should be 1")
+ self.assertEquals(r.stdout, b'', "QEMU stdout should be empty")
+ self.assertNotEquals(r.stderr, b'', "QEMU stderr shouldn't be empty")
--
2.18.0.rc1.1.g3f1ff2140
- [Qemu-devel] [PULL 00/11] Machine queue, 2019-04-25, Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 01/11] hw: add compat machines for 4.1, Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 02/11] vl.c: make find_default_machine() local, Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 03/11] vl.c: allocate TYPE_MACHINE list once during bootup, Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 04/11] vl: Clean up after previous commit, Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 05/11] vl: Simplify machine_parse(), Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 06/11] cpu: Rename parse_cpu_model() to parse_cpu_option(), Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 07/11] cpu: Fix crash with empty -cpu option,
Eduardo Habkost <=
- [Qemu-devel] [PULL 08/11] util/mmap-alloc: Add a 'is_pmem' parameter to qemu_ram_mmap, Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 09/11] scripts/update-linux-headers: add linux/mman.h, Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 10/11] linux-headers: add linux/mman.h., Eduardo Habkost, 2019/04/25
- [Qemu-devel] [PULL 11/11] util/mmap-alloc: support MAP_SYNC in qemu_ram_mmap(), Eduardo Habkost, 2019/04/25
- Re: [Qemu-devel] [PULL 00/11] Machine queue, 2019-04-25, Peter Maydell, 2019/04/26