Skip to content

Commit 0a24d7b

Browse files
committed
Avoid use-after-free in main thread
1 parent 17a3cb4 commit 0a24d7b

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

Zend/zend.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,14 +982,17 @@ int zend_post_startup(void) /* {{{ */
982982

983983
zend_destroy_rsrc_list(&EG(persistent_list));
984984
free(compiler_globals->function_table);
985+
compiler_globals->function_table = NULL;
985986
free(compiler_globals->class_table);
987+
compiler_globals->class_table = NULL;
986988
if ((script_encoding_list = (zend_encoding **)compiler_globals->script_encoding_list)) {
987989
compiler_globals_ctor(compiler_globals);
988990
compiler_globals->script_encoding_list = (const zend_encoding **)script_encoding_list;
989991
} else {
990992
compiler_globals_ctor(compiler_globals);
991993
}
992994
free(EG(zend_constants));
995+
EG(zend_constants) = NULL;
993996

994997
executor_globals_ctor(executor_globals);
995998
global_persistent_list = &EG(persistent_list);

ext/opcache/ZendAccelerator.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,27 +3051,33 @@ static void preload_shutdown(void)
30513051
zval *zv;
30523052

30533053
#if 0
3054-
ZEND_HASH_REVERSE_FOREACH_VAL(EG(zend_constants), zv) {
3055-
zend_constant *c = Z_PTR_P(zv);
3056-
if (ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT) {
3057-
break;
3058-
}
3059-
} ZEND_HASH_FOREACH_END_DEL();
3054+
if (EG(zend_constants)) {
3055+
ZEND_HASH_REVERSE_FOREACH_VAL(EG(zend_constants), zv) {
3056+
zend_constant *c = Z_PTR_P(zv);
3057+
if (ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT) {
3058+
break;
3059+
}
3060+
} ZEND_HASH_FOREACH_END_DEL();
3061+
}
30603062
#endif
30613063

3062-
ZEND_HASH_REVERSE_FOREACH_VAL(EG(function_table), zv) {
3063-
zend_function *func = Z_PTR_P(zv);
3064-
if (func->type == ZEND_INTERNAL_FUNCTION) {
3065-
break;
3066-
}
3067-
} ZEND_HASH_FOREACH_END_DEL();
3064+
if (EG(function_table)) {
3065+
ZEND_HASH_REVERSE_FOREACH_VAL(EG(function_table), zv) {
3066+
zend_function *func = Z_PTR_P(zv);
3067+
if (func->type == ZEND_INTERNAL_FUNCTION) {
3068+
break;
3069+
}
3070+
} ZEND_HASH_FOREACH_END_DEL();
3071+
}
30683072

3069-
ZEND_HASH_REVERSE_FOREACH_VAL(EG(class_table), zv) {
3070-
zend_class_entry *ce = Z_PTR_P(zv);
3071-
if (ce->type == ZEND_INTERNAL_CLASS) {
3072-
break;
3073-
}
3074-
} ZEND_HASH_FOREACH_END_DEL();
3073+
if (EG(class_table)) {
3074+
ZEND_HASH_REVERSE_FOREACH_VAL(EG(class_table), zv) {
3075+
zend_class_entry *ce = Z_PTR_P(zv);
3076+
if (ce->type == ZEND_INTERNAL_CLASS) {
3077+
break;
3078+
}
3079+
} ZEND_HASH_FOREACH_END_DEL();
3080+
}
30753081
}
30763082

30773083
static void preload_activate(void)

0 commit comments

Comments
 (0)