From 31833e6c4c6a28a1f5233ca3b1e86e79965ec131 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Mon, 28 Aug 2023 22:14:32 +0100 Subject: [PATCH] Expand file path in file stat only for wrapper path (#12068) --- ext/standard/filestat.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 83d1487a514..1beb0324638 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -727,28 +727,31 @@ PHPAPI void php_stat(zend_string *filename, int type, zval *return_value) if (wrapper == &php_plain_files_wrapper) { char realpath[MAXPATHLEN]; - if (expand_filepath(local, realpath) == NULL) { - strlcpy(realpath, local, sizeof(realpath)); + const char *file_path_to_check; + if (strstr(local, "://") == NULL || expand_filepath(local, realpath) == NULL) { + file_path_to_check = local; + } else { + file_path_to_check = realpath; } switch (type) { #ifdef F_OK case FS_EXISTS: - RETURN_BOOL(VCWD_ACCESS(realpath, F_OK) == 0); + RETURN_BOOL(VCWD_ACCESS(file_path_to_check, F_OK) == 0); break; #endif #ifdef W_OK case FS_IS_W: - RETURN_BOOL(VCWD_ACCESS(realpath, W_OK) == 0); + RETURN_BOOL(VCWD_ACCESS(file_path_to_check, W_OK) == 0); break; #endif #ifdef R_OK case FS_IS_R: - RETURN_BOOL(VCWD_ACCESS(realpath, R_OK) == 0); + RETURN_BOOL(VCWD_ACCESS(file_path_to_check, R_OK) == 0); break; #endif #ifdef X_OK case FS_IS_X: - RETURN_BOOL(VCWD_ACCESS(realpath, X_OK) == 0); + RETURN_BOOL(VCWD_ACCESS(file_path_to_check, X_OK) == 0); break; #endif }