From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:48429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hH57X-00045D-5P for qemu-devel@nongnu.org; Thu, 18 Apr 2019 07:22:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hH57W-0003zD-7V for qemu-devel@nongnu.org; Thu, 18 Apr 2019 07:22:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hH57W-0003yI-21 for qemu-devel@nongnu.org; Thu, 18 Apr 2019 07:22:22 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DD3C356F5 for ; Thu, 18 Apr 2019 11:22:21 +0000 (UTC) Date: Thu, 18 Apr 2019 13:22:16 +0200 From: Igor Mammedov Message-ID: <20190418132216.7a53f1ce@redhat.com> In-Reply-To: <20190418034501.5038-1-ehabkost@redhat.com> References: <20190418034501.5038-1-ehabkost@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] cpu: Fix crash with empty -cpu option List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eduardo Habkost Cc: qemu-devel@nongnu.org, Cleber Rosa On Thu, 18 Apr 2019 00:45:01 -0300 Eduardo Habkost wrote: > 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: commit 99193d8f2ef5 ("cpu: drop unnecessary NULL check and cpu_common_class_by_name()") > Signed-off-by: Eduardo Habkost > --- > 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 1ca95df9d8..d816b38863 100644 > --- a/exec.c > +++ b/exec.c > @@ -999,6 +999,10 @@ const char *parse_cpu_option(MachineState *machine, 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); s/1/EXIT_FAILURE/ > + } > > cc = lookup_cpu_class(model_pieces[0], &error_fatal); > cpu_type = object_class_get_name(OBJECT_CLASS(cc)); > 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 > +# > +# 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")