From nobody Sun May 5 21:32:16 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) 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=temperror (zoho.com: Error in retrieving data from DNS) 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=1555559205; cv=none; d=zoho.com; s=zohoarc; b=bg59gQtnvnHgfSDiY89eZxmaxgbkTefl8IdnEC0HyqDZPADN3V3Xhv3v+DLa9QKUovCeFDs4eQopR99QefTvQSuTT+ZtKutljdhvzLkoaSsyMhxC9DZbi0+/ouJ2y6ZFD5f2/YlBm7kIdWhfDElxrfFY+85d1R/xrbYeI1MT3Kw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555559205; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=sEToBVmr1zscZLbJEjjZKzg1V4bX2jfEw9P5ZEqjjE0=; b=V3vCfYimLuEiszPJFGpDILHfmI/PQWX3oRbLMB0X3NGTfdT9RoTMW510Yz6bI+AaimtHOvLQ/lsHCeh+0DqMgfveDW3koMHJfcnn4SlwbBDR7eDDLwtUmg3po+m8Tq8sS35/e4LV0UzM9wx/w43ZI8VXrXBFdmGCQMuTFuXRqRc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=temperror (zoho.com: Error in retrieving data from DNS) 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1555559204863640.328848898635; Wed, 17 Apr 2019 20:46:44 -0700 (PDT) Received: from localhost ([127.0.0.1]:35023 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGy0I-0006KX-C6 for importer@patchew.org; Wed, 17 Apr 2019 23:46:26 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hGxzD-0005pE-BD for qemu-devel@nongnu.org; Wed, 17 Apr 2019 23:45:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hGxz5-0005Ct-0l for qemu-devel@nongnu.org; Wed, 17 Apr 2019 23:45:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46738) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hGxz4-0005BF-7L for qemu-devel@nongnu.org; Wed, 17 Apr 2019 23:45:10 -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 220F930992B8 for ; Thu, 18 Apr 2019 03:45:07 +0000 (UTC) Received: from localhost (ovpn-116-9.gru2.redhat.com [10.97.116.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2C3A5D6A9; Thu, 18 Apr 2019 03:45:03 +0000 (UTC) From: Eduardo Habkost To: qemu-devel@nongnu.org Date: Thu, 18 Apr 2019 00:45:01 -0300 Message-Id: <20190418034501.5038-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.43]); Thu, 18 Apr 2019 03:45:07 +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] [PATCH] 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: , Cc: Igor Mammedov , Cleber Rosa 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: commit 99193d8f2ef5 ("cpu: drop unnecessary NULL check and cpu_commo= n_class_by_name()") Signed-off-by: Eduardo Habkost Reviewed-by: Stefano Garzarella Tested-by: Stefano Garzarella --- 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, co= nst 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 cc =3D lookup_cpu_class(model_pieces[0], &error_fatal); cpu_type =3D object_class_get_name(OBJECT_CLASS(cc)); 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