Skip to content

Commit 7174c44

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents 3e25ddb + a4acff3 commit 7174c44

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,29 @@ zend_op_array *file_cache_compile_file(zend_file_handle *file_handle, int type)
19061906
}
19071907
#endif
19081908

1909+
int check_persistent_script_access(zend_persistent_script *persistent_script)
1910+
{
1911+
char *phar_path, *ptr;
1912+
int ret;
1913+
if ((ZSTR_LEN(persistent_script->script.filename)<sizeof("phar://.phar")) ||
1914+
memcmp(ZSTR_VAL(persistent_script->script.filename), "phar://", sizeof("phar://")-1)) {
1915+
1916+
return access(ZSTR_VAL(persistent_script->script.filename), R_OK) != 0;
1917+
1918+
} else {
1919+
/* we got a cached file from .phar, so we have to strip prefix and path inside .phar to check access() */
1920+
phar_path = estrdup(ZSTR_VAL(persistent_script->script.filename)+sizeof("phar://")-1);
1921+
if ((ptr = strstr(phar_path, ".phar/")) != NULL)
1922+
{
1923+
*(ptr+sizeof(".phar/")-2) = 0; /* strip path inside .phar file */
1924+
}
1925+
ret = access(phar_path, R_OK) != 0;
1926+
efree(phar_path);
1927+
return ret;
1928+
}
1929+
}
1930+
1931+
19091932
/* zend_compile() replacement */
19101933
zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
19111934
{
@@ -2042,7 +2065,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
20422065
if (EXPECTED(persistent_script != NULL) &&
20432066
UNEXPECTED(ZCG(accel_directives).validate_permission) &&
20442067
file_handle->type == ZEND_HANDLE_FILENAME &&
2045-
UNEXPECTED(access(ZSTR_VAL(persistent_script->script.filename), R_OK) != 0)) {
2068+
UNEXPECTED(check_persistent_script_access(persistent_script))) {
20462069
if (type == ZEND_REQUIRE) {
20472070
zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename);
20482071
zend_bailout();

0 commit comments

Comments
 (0)