From: alexjlzheng@gmail.com
To: pbonzini@redhat.com, berrange@redhat.com, eduardo@habkost.net
Cc: qemu-devel@nongnu.org, Jinliang Zheng <alexjlzheng@tencent.com>
Subject: [PATCH] qom: fix NULL pointer in object_initialize_with_type()
Date: Sun, 15 Sep 2024 22:53:39 +0800 [thread overview]
Message-ID: <20240915145339.1368029-1-alexjlzheng@tencent.com> (raw)
From: Jinliang Zheng <alexjlzheng@tencent.com>
Currently, object_initialize_with_type() calls object_class_property_init_all()
before initializing Object->properties. This may cause Object->properties to
still be NULL when we call object_property_add() on Object.
For exmaple, if we extend DEFINE_PROP_ARRAY() to a version with a default value
other than 0:
#define DEFINE_PROP_ARRAY_EXAMPLE(_name, _state, _field, \
_arrayfield, _arrayprop, _arraytype) \
DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \
_state, _field, qdev_prop_arraylen_virtio_net, \
uint32_t, \
.set_default = true, \
.defval.u = <non-zero>, \
.arrayinfo = &(_arrayprop), \
.arrayfieldsize = sizeof(_arraytype), \
.arrayoffset = offsetof(_state, _arrayfield))
We should have:
object_initialize_with_type
object_class_property_init_all
ObjectProperty->init() / object_property_init_defval
...
set_prop_arraylen
object_property_add
object_property_try_add
g_hash_table_insert(Object->properties) <- NULL
obj->properties = g_hash_table_new_full() <- initializing
This patch fixes the above problem by exchanging the order of Ojbect->properties
initialization and object_class_property_init_all().
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
qom/object.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/qom/object.c b/qom/object.c
index 157a45c5f8..734b52f048 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -556,9 +556,9 @@ static void object_initialize_with_type(Object *obj, size_t size, TypeImpl *type
memset(obj, 0, type->instance_size);
obj->class = type->class;
object_ref(obj);
- object_class_property_init_all(obj);
obj->properties = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, object_property_free);
+ object_class_property_init_all(obj);
object_init_with_type(obj, type);
object_post_init_with_type(obj, type);
}
--
2.41.1
next reply other threads:[~2024-09-15 16:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-15 14:53 alexjlzheng [this message]
2024-09-24 2:44 ` [PATCH] qom: fix NULL pointer in object_initialize_with_type() Jinliang Zheng
2024-09-30 15:38 ` Peter Maydell
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=20240915145339.1368029-1-alexjlzheng@tencent.com \
--to=alexjlzheng@gmail.com \
--cc=alexjlzheng@tencent.com \
--cc=berrange@redhat.com \
--cc=eduardo@habkost.net \
--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).