summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2021-02-26 02:28:46 +0300
committerDmitry Stogov <dmitry@zend.com>2021-02-26 02:28:46 +0300
commit13e4ce386bb7257dbbe3167b070382ea959ec763 (patch)
treebf73295d32470a3e85d84dc244655f37c550c386 /main
parent5e8ae15c3d59f5ee4ca9f51b4ee712e2ada67864 (diff)
downloadphp-git-13e4ce386bb7257dbbe3167b070382ea959ec763.tar.gz
Improve SPL directory and stat() cache using zend_srting* instead of char*
Diffstat (limited to 'main')
-rw-r--r--main/php_streams.h2
-rw-r--r--main/streams/plain_wrapper.c12
-rw-r--r--main/streams/streams.c37
3 files changed, 9 insertions, 42 deletions
diff --git a/main/php_streams.h b/main/php_streams.h
index 60be0a79eb..f7196b8437 100644
--- a/main/php_streams.h
+++ b/main/php_streams.h
@@ -391,7 +391,7 @@ END_EXTERN_C()
/* Flags for url_stat method in wrapper ops */
#define PHP_STREAM_URL_STAT_LINK 1
#define PHP_STREAM_URL_STAT_QUIET 2
-#define PHP_STREAM_URL_STAT_NOCACHE 4
+#define PHP_STREAM_URL_STAT_IGNORE_OPEN_BASEDIR 4
/* change the blocking mode of stream: value == 1 => blocking, value == 0 => non-blocking. */
#define PHP_STREAM_OPTION_BLOCKING 1
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index a63c225a0d..58b5b64e0e 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -1157,12 +1157,14 @@ static php_stream *php_plain_files_stream_opener(php_stream_wrapper *wrapper, co
static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb, php_stream_context *context)
{
- if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) {
- url += sizeof("file://") - 1;
- }
+ if (!(flags & PHP_STREAM_URL_STAT_IGNORE_OPEN_BASEDIR)) {
+ if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) {
+ url += sizeof("file://") - 1;
+ }
- if (php_check_open_basedir_ex(url, (flags & PHP_STREAM_URL_STAT_QUIET) ? 0 : 1)) {
- return -1;
+ if (php_check_open_basedir_ex(url, (flags & PHP_STREAM_URL_STAT_QUIET) ? 0 : 1)) {
+ return -1;
+ }
}
#ifdef PHP_WIN32
diff --git a/main/streams/streams.c b/main/streams/streams.c
index e5e90e0f4d..96d3aeb41e 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -1975,47 +1975,12 @@ PHPAPI int _php_stream_stat_path(const char *path, int flags, php_stream_statbuf
{
php_stream_wrapper *wrapper = NULL;
const char *path_to_open = path;
- int ret;
memset(ssb, 0, sizeof(*ssb));
- if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) {
- /* Try to hit the cache first */
- if (flags & PHP_STREAM_URL_STAT_LINK) {
- if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) {
- memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf));
- return 0;
- }
- } else {
- if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) {
- memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf));
- return 0;
- }
- }
- }
-
wrapper = php_stream_locate_url_wrapper(path, &path_to_open, 0);
if (wrapper && wrapper->wops->url_stat) {
- ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context);
- if (ret == 0) {
- if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) {
- /* Drop into cache */
- if (flags & PHP_STREAM_URL_STAT_LINK) {
- if (BG(CurrentLStatFile)) {
- efree(BG(CurrentLStatFile));
- }
- BG(CurrentLStatFile) = estrdup(path);
- memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf));
- } else {
- if (BG(CurrentStatFile)) {
- efree(BG(CurrentStatFile));
- }
- BG(CurrentStatFile) = estrdup(path);
- memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf));
- }
- }
- }
- return ret;
+ return wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context);
}
return -1;
}