All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org, Cleber Rosa <crosa@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] cpu: Fix crash with empty -cpu option
Date: Thu, 18 Apr 2019 13:22:16 +0200	[thread overview]
Message-ID: <20190418132216.7a53f1ce@redhat.com> (raw)
In-Reply-To: <20190418034501.5038-1-ehabkost@redhat.com>

On Thu, 18 Apr 2019 00:45:01 -0300
Eduardo Habkost <ehabkost@redhat.com> 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 <ehabkost@redhat.com>
> ---
>  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 <ehabkost@redhat.com>
> +#
> +# 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")

  parent reply	other threads:[~2019-04-18 11:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-18  3:45 [Qemu-devel] [PATCH] cpu: Fix crash with empty -cpu option Eduardo Habkost
2019-04-18  3:45 ` Eduardo Habkost
2019-04-18  8:09 ` Stefano Garzarella
2019-04-18  8:09   ` Stefano Garzarella
2019-04-18 11:22 ` Igor Mammedov [this message]
2019-04-18 13:23   ` Eduardo Habkost
2019-04-18 15:05     ` Igor Mammedov
2019-04-18 20:16 ` Eduardo Habkost
2019-04-18 20:16   ` Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190418132216.7a53f1ce@redhat.com \
    --to=imammedo@redhat.com \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.