Skip to content

Fix use-after-free of constant name #12405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Zend/tests/gh12366.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

enum Level: int {
case Debug = 100;
}

var_dump(Level::Debug);
16 changes: 16 additions & 0 deletions Zend/tests/gh12366.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
GH-12366: Use-after-free of constant name when script doesn't fit in SHM
--EXTENSIONS--
opcache
--INI--
opcache.enable_cli=1
opcache.file_update_protection=1
--FILE--
<?php
$file = __DIR__ . '/gh12366.inc';
// Update timestamp and use opcache.file_update_protection=1 to prevent included file from being persisted in shm.
touch($file);
require $file;
?>
--EXPECT--
enum(Level::Debug)
2 changes: 2 additions & 0 deletions Zend/zend_enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ zend_result zend_enum_build_backed_enum_table(zend_class_entry *ce)
ZSTR_VAL(name));
goto failure;
}
Z_TRY_ADDREF_P(case_name);
zend_hash_index_add_new(backed_enum_table, long_key, case_name);
} else {
ZEND_ASSERT(ce->enum_backing_type == IS_STRING);
Expand All @@ -241,6 +242,7 @@ zend_result zend_enum_build_backed_enum_table(zend_class_entry *ce)
ZSTR_VAL(name));
goto failure;
}
Z_TRY_ADDREF_P(case_name);
zend_hash_add_new(backed_enum_table, string_key, case_name);
}
} ZEND_HASH_FOREACH_END();
Expand Down