Skip to content

Commit bcb9bc2

Browse files
committed
ext/opcache/ZendAccelerator: normalize all paths in persistent_compile_file()
This allows using ZIP-cached PHP sources with "include"/"require".
1 parent 255bb5d commit bcb9bc2

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ static void preload_shutdown(void);
138138
static void preload_activate(void);
139139
static void preload_restart(void);
140140

141+
static zend_string* normalize_path(const zend_string *src);
142+
141143
#ifdef HAVE_STDATOMIC_H
142144
# define INCREMENT(v) (++ZCSG(v))
143145
# define DECREMENT(v) (--ZCSG(v))
@@ -2008,14 +2010,12 @@ static int check_persistent_script_access(zend_persistent_script *persistent_scr
20082010
}
20092011

20102012
/* zend_compile() replacement */
2011-
zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2013+
static zend_op_array *persistent_compile_file_inner(zend_file_handle *file_handle, zend_string *const filename, int type)
20122014
{
20132015
zend_persistent_script *persistent_script = NULL;
20142016
zend_string *key = NULL;
20152017
bool from_shared_memory; /* if the script we've got is stored in SHM */
20162018

2017-
zend_string *filename = file_handle->filename;
2018-
20192019
if (!filename || !ZCG(accelerator_enabled)) {
20202020
/* The Accelerator is disabled, act as if without the Accelerator */
20212021
ZCG(cache_opline) = NULL;
@@ -2285,6 +2285,31 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
22852285
return zend_accel_load_script(persistent_script, from_shared_memory);
22862286
}
22872287

2288+
/* zend_compile() replacement */
2289+
zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2290+
{
2291+
zend_string *filename = file_handle->filename;
2292+
2293+
zend_string *allocated_filename = NULL;
2294+
if (filename && ZCG(accelerator_enabled) && !file_cache_only &&
2295+
!is_stream_path(ZSTR_VAL(filename)) && (type == ZEND_INCLUDE || type == ZEND_REQUIRE)) {
2296+
/* zend_include_or_eval() calls zend_resolve_path()
2297+
only for ZEND_INCLUDE_ONCE and ZEND_REQUIRE_ONCE;
2298+
for ZEND_INCLUDE/ZEND_REQUIRE, we need to do that
2299+
here so lookups in the ZIP file work */
2300+
filename = allocated_filename = normalize_path(filename);
2301+
}
2302+
2303+
zend_op_array *op_array = persistent_compile_file_inner(file_handle, filename, type);
2304+
2305+
if (allocated_filename) {
2306+
/* free the normalized filename */
2307+
zend_string_efree(allocated_filename);
2308+
}
2309+
2310+
return op_array;
2311+
}
2312+
22882313
static zend_always_inline zend_inheritance_cache_entry* zend_accel_inheritance_cache_find(zend_inheritance_cache_entry *entry, zend_class_entry *ce, zend_class_entry *parent, zend_class_entry **traits_and_interfaces, bool *needs_autoload_ptr)
22892314
{
22902315
uint32_t i;

0 commit comments

Comments
 (0)