core: object: validate magic number in object header

This commit is contained in:
2025-11-01 09:56:22 +00:00
parent 053dd26304
commit 360428c8e8

View File

@@ -2,6 +2,7 @@
#include "type.h"
#include <assert.h>
#include <blue/core/class.h>
#include <blue/core/macros.h>
#include <blue/core/object.h>
@@ -98,6 +99,8 @@ void *b_object_get_private(const struct _b_object *object, b_type type)
return NULL;
}
assert(object->obj_magic == B_OBJECT_MAGIC);
if (b_type_id_compare(&object->obj_type->r_info->t_id, type) == 0) {
return (char *)object + object->obj_main_priv_offset;
}
@@ -117,6 +120,8 @@ void *b_object_get_protected(const struct _b_object *object, b_type type)
return NULL;
}
assert(object->obj_magic == B_OBJECT_MAGIC);
struct b_type_component *comp
= b_type_get_component(&object->obj_type->r_components, type);
if (!comp) {
@@ -132,6 +137,8 @@ void *b_object_get_interface(const struct _b_object *object, b_type type)
return NULL;
}
assert(object->obj_magic == B_OBJECT_MAGIC);
return b_class_get_interface(object->obj_type->r_class, type);
}
@@ -143,6 +150,8 @@ enum b_status b_object_get_data(
return B_ERR_INVALID_ARGUMENT;
}
assert(object->obj_magic == B_OBJECT_MAGIC);
struct b_type_component *comp
= b_type_get_component(&object->obj_type->r_components, type);
if (!comp) {