From fe4152c6a559c9b30575ee5115ce7b6822eeaa46 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Sat, 3 Mar 2018 22:17:13 -0500 Subject: [PATCH] qom: enforce readonly nature of link's check callback link's check callback is supposed to verify/permit setting it, however currently nothing restricts it from misusing it and modifying target object from within. Make sure that readonly semantics are checked by compiler to prevent callback's misuse. Backports commit 8f5d58ef2c92d7b82d9a6eeefd7c8854a183ba4a from qemu --- qemu/include/qom/object.h | 6 +++--- qemu/qom/object.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/qemu/include/qom/object.h b/qemu/include/qom/object.h index bb915186..b7d452e8 100644 --- a/qemu/include/qom/object.h +++ b/qemu/include/qom/object.h @@ -651,7 +651,7 @@ ObjectClass *object_get_class(Object *obj); * * Returns: The QOM typename of @obj. */ -const char *object_get_typename(Object *obj); +const char *object_get_typename(const Object *obj); /** * type_register_static: @@ -1165,7 +1165,7 @@ typedef enum { * callback function. It allows the link property to be set and never returns * an error. */ -void object_property_allow_set_link(Object *, const char *, +void object_property_allow_set_link(const Object *, const char *, Object *, Error **); /** @@ -1198,7 +1198,7 @@ void object_property_allow_set_link(Object *, const char *, */ void object_property_add_link(struct uc_struct *uc, Object *obj, const char *name, const char *type, Object **child, - void (*check)(Object *obj, const char *name, + void (*check)(const Object *obj, const char *name, Object *val, Error **errp), ObjectPropertyLinkFlags flags, Error **errp); diff --git a/qemu/qom/object.c b/qemu/qom/object.c index 87810218..9e16e29e 100644 --- a/qemu/qom/object.c +++ b/qemu/qom/object.c @@ -616,7 +616,7 @@ out: return ret; } -const char *object_get_typename(Object *obj) +const char *object_get_typename(const Object *obj) { return obj->class->type->name; } @@ -1211,7 +1211,7 @@ out: g_free(type); } -void object_property_allow_set_link(Object *obj, const char *name, +void object_property_allow_set_link(const Object *obj, const char *name, Object *val, Error **errp) { /* Allow the link to be set, always */ @@ -1219,7 +1219,7 @@ void object_property_allow_set_link(Object *obj, const char *name, typedef struct { Object **child; - void (*check)(Object *, const char *, Object *, Error **); + void (*check)(const Object *, const char *, Object *, Error **); ObjectPropertyLinkFlags flags; } LinkProperty; @@ -1337,7 +1337,7 @@ static void object_release_link_property(struct uc_struct *uc, Object *obj, cons void object_property_add_link(struct uc_struct *uc, Object *obj, const char *name, const char *type, Object **child, - void (*check)(Object *, const char *, + void (*check)(const Object *, const char *, Object *, Error **), ObjectPropertyLinkFlags flags, Error **errp)