From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: qemu-devel@nongnu.org
Cc: Alexey Kardashevskiy <aik@ozlabs.ru>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH qemu v3 1/2] object: Handle objects with no parents
Date: Wed, 30 May 2018 17:17:56 +1000 [thread overview]
Message-ID: <20180530071757.9112-2-aik@ozlabs.ru> (raw)
In-Reply-To: <20180530071757.9112-1-aik@ozlabs.ru>
At the moment object_get_canonical_path() crashes if the object or one
of its parents does not have a parent, for example, a KVM accelerator
object.
This adds a check for obj!=NULL in a loop to prevent the crash.
In order not to return a wrong path, this checks for currently resolved
partial path and does not add a leading slash to tell the reader that
the path is partial as the owner object is detached.
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
I have not tested the case with obj==NULL and path!=NULL as this is
for objects which have parents which are not attached to the root
and we do not have such objects in current QEMU afaict but I kept it
just in case.
---
Changes:
v3:
* do not check for obj->parent
* return NULL or incomplete path depending on the situation
---
qom/object.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index 0fc9720..05138ba 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1669,7 +1669,7 @@ gchar *object_get_canonical_path(Object *obj)
Object *root = object_get_root();
char *newpath, *path = NULL;
- while (obj != root) {
+ while (obj && obj != root) {
char *component = object_get_canonical_path_component(obj);
if (path) {
@@ -1684,7 +1684,13 @@ gchar *object_get_canonical_path(Object *obj)
obj = obj->parent;
}
- newpath = g_strdup_printf("/%s", path ? path : "");
+ if (obj && path) {
+ newpath = g_strdup_printf("/%s", path);
+ } else if (path) {
+ newpath = g_strdup(path);
+ } else {
+ newpath = NULL;
+ }
g_free(path);
return newpath;
--
2.11.0
next prev parent reply other threads:[~2018-05-30 7:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-30 7:17 [Qemu-devel] [PATCH qemu v3 0/2] memory/hmp: Print owners/parents in "info mtree" Alexey Kardashevskiy
2018-05-30 7:17 ` Alexey Kardashevskiy [this message]
2018-05-30 16:42 ` [Qemu-devel] [PATCH qemu v3 1/2] object: Handle objects with no parents Paolo Bonzini
2018-05-30 7:17 ` [Qemu-devel] [PATCH qemu v3 2/2] memory/hmp: Print owners/parents in "info mtree" Alexey Kardashevskiy
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=20180530071757.9112-2-aik@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=armbru@redhat.com \
--cc=dgilbert@redhat.com \
--cc=pbonzini@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).