qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Alexey Kardashevskiy <aik@ozlabs.ru>, qemu-devel@nongnu.org
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>
Subject: Re: [Qemu-devel] [PATCH qemu v2 2/2] object: Handle objects with no parents
Date: Mon, 30 Apr 2018 11:51:07 +0200	[thread overview]
Message-ID: <80d34e0f-b9e5-df5c-8464-0a15df26e1ca@redhat.com> (raw)
In-Reply-To: <20180430062536.49077-3-aik@ozlabs.ru>

On 30/04/2018 08:25, Alexey Kardashevskiy wrote:
> At the moment object_get_canonical_path_component() crashes on assert()
> if the object does not have a parent. Usually it is not called for
> orphan objects but various HMP/QMP commands can do that (info mtree,
> qom-get).
> 
> This adds few more tests in object_get_canonical_path() to prevent QEMU
> from crashing.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> ---
>  qom/object.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 4677951..e0e300b 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -1668,7 +1668,7 @@ gchar *object_get_canonical_path(Object *obj)
>      Object *root = object_get_root();
>      char *newpath, *path = NULL;
>  
> -    while (obj != root) {
> +    while (obj && obj->parent && obj != root) {
>          char *component = object_get_canonical_path_component(obj);
>  
>          if (path) {

I think the patch is a good idea, but as it is written it is incorrect,
because it will return an invalid canonical path.  You should return
NULL instead.

Also, checking both obj and obj->parent is unnecessary; if obj->parent
is NULL, obj will be NULL on the next iteration.

Thanks,

Paolo

      reply	other threads:[~2018-04-30  9:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30  6:25 [Qemu-devel] [PATCH qemu v2 0/2] memory/hmp: Print owners/parents in "info mtree" Alexey Kardashevskiy
2018-04-30  6:25 ` [Qemu-devel] [PATCH qemu v2 1/2] " Alexey Kardashevskiy
2018-04-30  9:53   ` Paolo Bonzini
2018-05-03  5:40     ` Alexey Kardashevskiy
2018-05-30  4:57       ` Alexey Kardashevskiy
2018-05-30 10:30         ` Paolo Bonzini
2018-04-30  6:25 ` [Qemu-devel] [PATCH qemu v2 2/2] object: Handle objects with no parents Alexey Kardashevskiy
2018-04-30  9:51   ` Paolo Bonzini [this message]

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=80d34e0f-b9e5-df5c-8464-0a15df26e1ca@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aik@ozlabs.ru \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=imammedo@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).