From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Andreas Faerber <afaerber@suse.de>,
Anthony Liguori <aliguori@amazon.com>,
Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PATCH RESEND v4 2/5] qom: don't make link NULL on object_property_set_link() failure
Date: Wed, 19 Mar 2014 08:58:54 +0100 [thread overview]
Message-ID: <1395215937-22987-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1395215937-22987-1-git-send-email-stefanha@redhat.com>
The error behavior of object_property_set_link() is dangerous. It sets
the link property object to NULL if an error occurs. A setter function
should either succeed or fail, it shouldn't leave the value NULL on
failure.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
qom/object.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index da49474..25fc04c 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1079,27 +1079,28 @@ static Object *object_resolve_link(Object *obj, const char *name,
static void object_set_link_property(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
+ Error *local_err = NULL;
Object **child = opaque;
- Object *old_target;
- char *path;
-
- visit_type_str(v, &path, name, errp);
+ Object *old_target = *child;
+ Object *new_target = NULL;
+ char *path = NULL;
- old_target = *child;
- *child = NULL;
+ visit_type_str(v, &path, name, &local_err);
- if (strcmp(path, "") != 0) {
- Object *target;
-
- target = object_resolve_link(obj, name, path, errp);
- if (target) {
- object_ref(target);
- *child = target;
- }
+ if (!local_err && strcmp(path, "") != 0) {
+ new_target = object_resolve_link(obj, name, path, &local_err);
}
g_free(path);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ if (new_target) {
+ object_ref(new_target);
+ }
+ *child = new_target;
if (old_target != NULL) {
object_unref(old_target);
}
--
1.8.5.3
next prev parent reply other threads:[~2014-03-19 10:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-19 7:58 [Qemu-devel] [PATCH RESEND v4 0/5] qom: link property fixes Stefan Hajnoczi
2014-03-19 7:58 ` [Qemu-devel] [PATCH RESEND v4 1/5] qom: split object_property_set_link() Stefan Hajnoczi
2014-03-19 21:16 ` Andreas Färber
2014-03-19 7:58 ` Stefan Hajnoczi [this message]
2014-03-19 7:58 ` [Qemu-devel] [PATCH RESEND v4 3/5] qom: make QOM link property unref optional Stefan Hajnoczi
2014-03-19 7:58 ` [Qemu-devel] [PATCH RESEND v4 4/5] qom: add check() argument to object_property_add_link() Stefan Hajnoczi
2014-03-19 21:27 ` Andreas Färber
2014-03-19 7:58 ` [Qemu-devel] [PATCH RESEND v4 5/5] virtio-rng: avoid default_backend refcount leak Stefan Hajnoczi
2014-03-19 15:55 ` [Qemu-devel] [PATCH RESEND v4 0/5] qom: link property fixes Paolo Bonzini
2014-03-19 21:29 ` Andreas Färber
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=1395215937-22987-3-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--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).