Skip to content

Commit 4dc0662

Browse files
committed
Check for NULL GC type in objects_store_del
This might happen if OBJ_RELEASE is used on an object that was already released by GC. Specific cases of this issue were previously fixed in ffaee27 and 72104d2, however the issue still affects 3rd-party extensions using OBJ_RELEASE. The whole GC type NULL + OBJ_IS_VALID + IS_FREE_CALLED system seems overly complicated and can probably be simplified in 7.4.
1 parent d63a7aa commit 4dc0662

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Zend/zend_generators.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ ZEND_API void zend_generator_close(zend_generator *generator, zend_bool finished
123123
/* always free the CV's, in the symtable are only not-free'd IS_INDIRECT's */
124124
zend_free_compiled_variables(execute_data);
125125

126-
if ((EX_CALL_INFO() & ZEND_CALL_RELEASE_THIS) &&
127-
EXPECTED(GC_TYPE(Z_OBJ(execute_data->This)) == IS_OBJECT)) {
126+
if (EX_CALL_INFO() & ZEND_CALL_RELEASE_THIS) {
128127
OBJ_RELEASE(Z_OBJ(execute_data->This));
129128
}
130129

@@ -144,8 +143,7 @@ ZEND_API void zend_generator_close(zend_generator *generator, zend_bool finished
144143
}
145144

146145
/* Free closure object */
147-
if ((EX_CALL_INFO() & ZEND_CALL_CLOSURE) &&
148-
EXPECTED(GC_TYPE(ZEND_CLOSURE_OBJECT(EX(func))) == IS_OBJECT)) {
146+
if (EX_CALL_INFO() & ZEND_CALL_CLOSURE) {
149147
OBJ_RELEASE(ZEND_CLOSURE_OBJECT(EX(func)));
150148
}
151149

Zend/zend_objects_API.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,17 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_put(zend_object *object)
152152

153153
ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object) /* {{{ */
154154
{
155+
ZEND_ASSERT(GC_REFCOUNT(object) == 0);
156+
157+
/* GC might have released this object already. */
158+
if (UNEXPECTED(GC_TYPE(object) == IS_NULL)) {
159+
return;
160+
}
161+
155162
/* Make sure we hold a reference count during the destructor call
156163
otherwise, when the destructor ends the storage might be freed
157164
when the refcount reaches 0 a second time
158165
*/
159-
ZEND_ASSERT(EG(objects_store).object_buckets != NULL);
160-
ZEND_ASSERT(IS_OBJ_VALID(EG(objects_store).object_buckets[object->handle]));
161-
ZEND_ASSERT(GC_REFCOUNT(object) == 0);
162-
163166
if (!(OBJ_FLAGS(object) & IS_OBJ_DESTRUCTOR_CALLED)) {
164167
GC_ADD_FLAGS(object, IS_OBJ_DESTRUCTOR_CALLED);
165168

@@ -176,6 +179,8 @@ ZEND_API void ZEND_FASTCALL zend_objects_store_del(zend_object *object) /* {{{ *
176179
uint32_t handle = object->handle;
177180
void *ptr;
178181

182+
ZEND_ASSERT(EG(objects_store).object_buckets != NULL);
183+
ZEND_ASSERT(IS_OBJ_VALID(EG(objects_store).object_buckets[object->handle]));
179184
EG(objects_store).object_buckets[handle] = SET_OBJ_INVALID(object);
180185
if (!(OBJ_FLAGS(object) & IS_OBJ_FREE_CALLED)) {
181186
GC_ADD_FLAGS(object, IS_OBJ_FREE_CALLED);

0 commit comments

Comments
 (0)