From nobody Mon Feb 9 09:51:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1556215309; cv=none; d=zoho.com; s=zohoarc; b=AikSa0ssSmTLo0cwYpaa9r5p/rdo+HXK9wfu/vsYuaqVaav49UbLnmOQOQ7xpK2q38GioI3hhtTjjZF9YfHzLyId7mwiL9qZYulh9LG823reKkkM/W7y8KlTydbCkyPkeyPIgwyCts9XuYjGJ3WQL62OUZFz2E/J4pyNxzESsyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1556215309; h=Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=mJATqdEsu4CH6yPDH9TwozmBt64zhCW9N8E9k/BEQRM=; b=UyOHT2Zv3pv5Tc1+GYvZAjmTo9NpBirrU/0PPZNn+sCHlFirTUyZXHwQ7oXUzgONiuydTteQI9bC4nvReDxXb3VmB7hFhW0DsPROqDVutyidbRGVteusIzc+J6LC1VQQeZZHSczAIALBzUSLCUDDMkolJB6r06rs2AVe0HlCHHI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1556215309201208.8800367899754; Thu, 25 Apr 2019 11:01:49 -0700 (PDT) Received: from localhost ([127.0.0.1]:33315 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJigp-0003uU-81 for importer@patchew.org; Thu, 25 Apr 2019 14:01:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hJicb-0000Qf-AK for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hJicZ-00057i-AB for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30517) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hJicX-00052x-D0 for qemu-devel@nongnu.org; Thu, 25 Apr 2019 13:57:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B21981F13; Thu, 25 Apr 2019 17:57:16 +0000 (UTC) Received: from localhost (ovpn-116-9.gru2.redhat.com [10.97.116.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EC6E5D705; Thu, 25 Apr 2019 17:57:15 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell , qemu-devel@nongnu.org, Marcel Apfelbaum Date: Thu, 25 Apr 2019 14:56:55 -0300 Message-Id: <20190425175659.24876-8-ehabkost@redhat.com> In-Reply-To: <20190425175659.24876-1-ehabkost@redhat.com> References: <20190425175659.24876-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 25 Apr 2019 17:57:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 07/11] cpu: Fix crash with empty -cpu option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Message-Id: <20190418034501.5038-1-ehabkost@redhat.com> Reviewed-by: Stefano Garzarella Tested-by: Stefano Garzarella 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 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; =20 model_pieces =3D g_strsplit(cpu_option, ",", 2); + if (!model_pieces[0]) { + error_report("-cpu option cannot be empty"); + exit(1); + } =20 oc =3D cpu_class_by_name(CPU_RESOLVING_TYPE, model_pieces[0]); if (oc =3D=3D NULL) { diff --git a/tests/acceptance/empty_cpu_model.py b/tests/acceptance/empty_c= pu_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 =3D [self.qemu_bin, '-S', '-display', 'none', '-machine', 'non= e', '-cpu', ''] + r =3D subprocess.run(cmd, stderr=3Dsubprocess.PIPE, stdout=3Dsubpr= ocess.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 empt= y") --=20 2.18.0.rc1.1.g3f1ff2140