[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH qemu v2 2/2] object: Handle objects with no pare
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH qemu v2 2/2] object: Handle objects with no parents |
Date: |
Mon, 30 Apr 2018 11:51:07 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 |
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 <address@hidden>
> ---
> 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