Skip to content

Commit fcaa554

Browse files
committed
Ensure that statically stored class entries have an header
1 parent a286529 commit fcaa554

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

Zend/zend.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ struct _zend_class_entry {
253253
} info;
254254
};
255255

256+
typedef char zend_class_entry_storage[ZEND_CLASS_ENTRY_HEADER_SIZE + sizeof(zend_class_entry)];
257+
258+
#define ZEND_CES_TO_CE(ces) ((zend_class_entry*)((char*) (ces) + ZEND_CLASS_ENTRY_HEADER_SIZE))
259+
256260
typedef struct _zend_utility_functions {
257261
void (*error_function)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
258262
size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3359,7 +3359,7 @@ ZEND_API int zend_next_free_module(void) /* {{{ */
33593359

33603360
static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class_entry, uint32_t ce_flags) /* {{{ */
33613361
{
3362-
void *ref = malloc(sizeof(zend_class_entry) + ZEND_CLASS_ENTRY_HEADER_SIZE);
3362+
zend_class_entry_storage *ref = (zend_class_entry_storage*) malloc(sizeof(zend_class_entry) + ZEND_CLASS_ENTRY_HEADER_SIZE);
33633363
zend_class_entry *class_entry = zend_init_class_entry_header(ref);
33643364
zend_string *lowercase_name;
33653365
*class_entry = *orig_class_entry;

Zend/zend_compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8270,8 +8270,8 @@ static void zend_compile_generic_params(zend_ast *params_ast)
82708270
}
82718271
}
82728272

8273-
zend_class_entry *zend_init_class_entry_header(void *ptr) {
8274-
zend_class_reference *ref = ptr;
8273+
zend_class_entry *zend_init_class_entry_header(zend_class_entry_storage *ptr) {
8274+
zend_class_reference *ref = (zend_class_reference*) ptr;
82758275
zend_class_entry *ce = (zend_class_entry *) ((char *) ptr + ZEND_CLASS_ENTRY_HEADER_SIZE);
82768276
ref->ce = ce;
82778277
ref->args.num_types = 0;

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ ZEND_API void pass_two(zend_op_array *op_array);
909909
ZEND_API bool zend_is_compiling(void);
910910
ZEND_API char *zend_make_compiled_string_description(const char *name);
911911
ZEND_API void zend_initialize_class_data(zend_class_entry *ce, bool nullify_handlers);
912-
zend_class_entry *zend_init_class_entry_header(void *ptr);
912+
zend_class_entry *zend_init_class_entry_header(zend_class_entry_storage *ptr);
913913
uint32_t zend_get_class_fetch_type(const zend_string *name);
914914
ZEND_API uint8_t zend_get_call_op(const zend_op *init_op, zend_function *fbc);
915915
ZEND_API bool zend_is_smart_branch(const zend_op *opline);

Zend/zend_exceptions.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ ZEND_API zend_class_entry *zend_ce_division_by_zero_error;
4545
ZEND_API zend_class_entry *zend_ce_unhandled_match_error;
4646

4747
/* Internal pseudo-exception that is not exposed to userland. Throwing this exception *does not* execute finally blocks. */
48-
static zend_class_entry zend_ce_unwind_exit;
48+
static zend_class_entry_storage zend_ces_unwind_exit;
49+
#define zend_ce_unwind_exit ZEND_CES_TO_CE(zend_ces_unwind_exit)
4950

5051
/* Internal pseudo-exception that is not exposed to userland. Throwing this exception *does* execute finally blocks. */
51-
static zend_class_entry zend_ce_graceful_exit;
52+
static zend_class_entry_storage zend_ces_graceful_exit;
53+
#define zend_ce_graceful_exit ZEND_CES_TO_CE(zend_ces_graceful_exit)
5254

5355
ZEND_API void (*zend_throw_exception_hook)(zend_object *ex);
5456

@@ -795,9 +797,11 @@ void zend_register_default_exception(void) /* {{{ */
795797
zend_ce_unhandled_match_error = register_class_UnhandledMatchError(zend_ce_error);
796798
zend_init_exception_class_entry(zend_ce_unhandled_match_error);
797799

798-
INIT_CLASS_ENTRY(zend_ce_unwind_exit, "UnwindExit", NULL);
800+
INIT_CLASS_ENTRY((*zend_ce_unwind_exit), "UnwindExit", NULL);
801+
zend_init_class_entry_header(&zend_ces_unwind_exit);
799802

800-
INIT_CLASS_ENTRY(zend_ce_graceful_exit, "GracefulExit", NULL);
803+
INIT_CLASS_ENTRY((*zend_ce_graceful_exit), "GracefulExit", NULL);
804+
zend_init_class_entry_header(&zend_ces_graceful_exit);
801805
}
802806
/* }}} */
803807

@@ -958,7 +962,7 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
958962

959963
zend_string_release_ex(str, 0);
960964
zend_string_release_ex(file, 0);
961-
} else if (ce_exception == &zend_ce_unwind_exit || ce_exception == &zend_ce_graceful_exit) {
965+
} else if (ce_exception == zend_ce_unwind_exit || ce_exception == zend_ce_graceful_exit) {
962966
/* We successfully unwound, nothing more to do.
963967
* We still return FAILURE in this case, as further execution should still be aborted. */
964968
} else {
@@ -1006,12 +1010,12 @@ ZEND_API ZEND_COLD void zend_throw_exception_object(zval *exception) /* {{{ */
10061010

10071011
ZEND_API ZEND_COLD zend_object *zend_create_unwind_exit(void)
10081012
{
1009-
return zend_objects_new(&zend_ce_unwind_exit);
1013+
return zend_objects_new(zend_ce_unwind_exit);
10101014
}
10111015

10121016
ZEND_API ZEND_COLD zend_object *zend_create_graceful_exit(void)
10131017
{
1014-
return zend_objects_new(&zend_ce_graceful_exit);
1018+
return zend_objects_new(zend_ce_graceful_exit);
10151019
}
10161020

10171021
ZEND_API ZEND_COLD void zend_throw_unwind_exit(void)
@@ -1032,10 +1036,10 @@ ZEND_API ZEND_COLD void zend_throw_graceful_exit(void)
10321036

10331037
ZEND_API bool zend_is_unwind_exit(const zend_object *ex)
10341038
{
1035-
return OBJ_CE(ex) == &zend_ce_unwind_exit;
1039+
return ex->cr == (zend_class_reference*) &zend_ces_unwind_exit;
10361040
}
10371041

10381042
ZEND_API bool zend_is_graceful_exit(const zend_object *ex)
10391043
{
1040-
return OBJ_CE(ex) == &zend_ce_graceful_exit;
1044+
return ex->cr == (zend_class_reference*) &zend_ces_graceful_exit;
10411045
}

Zend/zend_iterators.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#include "zend.h"
2121
#include "zend_API.h"
2222

23-
static zend_class_entry zend_iterator_class_entry;
23+
static zend_class_entry_storage zend_iterator_class_entry_storage;
24+
#define zend_iterator_class_entry ZEND_CES_TO_CE(&zend_iterator_class_entry_storage)
2425

2526
static void iter_wrapper_free(zend_object *object);
2627
static void iter_wrapper_dtor(zend_object *object);
@@ -56,8 +57,9 @@ static const zend_object_handlers iterator_object_handlers = {
5657

5758
ZEND_API void zend_register_iterator_wrapper(void)
5859
{
59-
INIT_CLASS_ENTRY(zend_iterator_class_entry, "__iterator_wrapper", NULL);
60-
zend_iterator_class_entry.default_object_handlers = &iterator_object_handlers;
60+
INIT_CLASS_ENTRY((*zend_iterator_class_entry), "__iterator_wrapper", NULL);
61+
zend_iterator_class_entry->default_object_handlers = &iterator_object_handlers;
62+
zend_init_class_entry_header(&zend_iterator_class_entry_storage);
6163
}
6264

6365
static void iter_wrapper_free(zend_object *object)
@@ -83,7 +85,7 @@ static HashTable *iter_wrapper_get_gc(zend_object *object, zval **table, int *n)
8385

8486
ZEND_API void zend_iterator_init(zend_object_iterator *iter)
8587
{
86-
zend_object_std_init(&iter->std, &zend_iterator_class_entry);
88+
zend_object_std_init(&iter->std, zend_iterator_class_entry);
8789
}
8890

8991
ZEND_API void zend_iterator_dtor(zend_object_iterator *iter)

0 commit comments

Comments
 (0)