Skip to content

Instantly share code, notes, and snippets.

@rlerdorf
Created March 27, 2021 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlerdorf/bd7f1eab6b3df8a9318ec2e099f3fdd4 to your computer and use it in GitHub Desktop.
Save rlerdorf/bd7f1eab6b3df8a9318ec2e099f3fdd4 to your computer and use it in GitHub Desktop.
diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c
index 71f9781442..042d828d58 100644
--- a/Zend/zend_virtual_cwd.c
+++ b/Zend/zend_virtual_cwd.c
@@ -897,7 +897,7 @@ retry_reparse_tag_cloud:
tmp = do_alloca(len+1, use_heap);
memcpy(tmp, path, len+1);
- if (save && S_ISLNK(st.st_mode)) {
+ if (save && S_ISLNK(st.st_mode) && CWDG(resolve_symlinks)) {
if (++(*ll) > LINK_MAX || (j = (size_t)php_sys_readlink(tmp, path, MAXPATHLEN)) == (size_t)-1) {
/* too many links or broken symlinks */
free_alloca(tmp, use_heap);
@@ -929,7 +929,7 @@ retry_reparse_tag_cloud:
}
} else {
if (save) {
- directory = S_ISDIR(st.st_mode);
+ directory = S_ISDIR(st.st_mode) || (S_ISLNK(st.st_mode) && !CWDG(resolve_symlinks));
if (link_is_dir) {
*link_is_dir = directory;
}
diff --git a/Zend/zend_virtual_cwd.h b/Zend/zend_virtual_cwd.h
index dfaa95932c..f51f3f1bfa 100644
--- a/Zend/zend_virtual_cwd.h
+++ b/Zend/zend_virtual_cwd.h
@@ -224,6 +224,7 @@ typedef struct _virtual_cwd_globals {
zend_long realpath_cache_size_limit;
zend_long realpath_cache_ttl;
realpath_cache_bucket *realpath_cache[1024];
+ zend_bool resolve_symlinks;
} virtual_cwd_globals;
#ifdef ZTS
diff --git a/main/main.c b/main/main.c
index 881ae6e642..fdda2acca2 100644
--- a/main/main.c
+++ b/main/main.c
@@ -727,6 +727,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("realpath_cache_size", "4096K", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_size_limit, virtual_cwd_globals, cwd_globals)
STD_PHP_INI_ENTRY("realpath_cache_ttl", "120", PHP_INI_SYSTEM, OnUpdateLong, realpath_cache_ttl, virtual_cwd_globals, cwd_globals)
+ STD_PHP_INI_BOOLEAN("resolve_symlinks", "1", PHP_INI_SYSTEM, OnUpdateBool, resolve_symlinks, virtual_cwd_globals, cwd_globals)
STD_PHP_INI_ENTRY("user_ini.filename", ".user.ini", PHP_INI_SYSTEM, OnUpdateString, user_ini_filename, php_core_globals, core_globals)
STD_PHP_INI_ENTRY("user_ini.cache_ttl", "300", PHP_INI_SYSTEM, OnUpdateLong, user_ini_cache_ttl, php_core_globals, core_globals)
@@ -2023,6 +2024,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
}
sapi_module = *sf;
+ CWDG(resolve_symlinks) = 1;
php_output_startup();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment