diff options
author | Stanislav Malyshev <stas@php.net> | 2014-11-30 17:07:02 -0800 |
---|---|---|
committer | Stanislav Malyshev <stas@php.net> | 2014-11-30 17:07:02 -0800 |
commit | 60d5b2ec24625e399b862eb1dff92c32d54386c7 (patch) | |
tree | c657745c25cb36702f68b5797b0733053293d9f8 | |
parent | f6aa6324fbfe981847926d3e048f83bd4b468704 (diff) | |
parent | 04808aa7e18ad0b2f6d014d06777b519e41dbccf (diff) | |
download | php-git-60d5b2ec24625e399b862eb1dff92c32d54386c7.tar.gz |
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5:
Added test and review suggestion
Fix bug #68335: rmdir doesnt work with file:// stream wrapper
-rw-r--r-- | ext/standard/tests/file/bug68335.phpt | 13 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 45 |
2 files changed, 29 insertions, 29 deletions
diff --git a/ext/standard/tests/file/bug68335.phpt b/ext/standard/tests/file/bug68335.phpt new file mode 100644 index 0000000000..63eda4d923 --- /dev/null +++ b/ext/standard/tests/file/bug68335.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #68335: rmdir doesnt work with file:// stream wrapper +--FILE-- +<?php +$dir = 'file://' . dirname(__FILE__) . '/testDir'; +mkdir($dir); +var_dump(is_dir($dir)); +rmdir($dir); +var_dump(is_dir($dir)); +?> +--EXPECT-- +bool(true) +bool(false) diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 69c6a3ce26..6d8b5c203d 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -1025,12 +1025,8 @@ 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 TSRMLS_DC) { - char *p; - - if ((p = strstr(url, "://")) != NULL) { - if (p < strchr(url, '/')) { - url = p + 3; - } + 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 TSRMLS_CC)) { @@ -1055,13 +1051,10 @@ static int php_plain_files_url_stater(php_stream_wrapper *wrapper, const char *u static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) { - char *p; int ret; - if ((p = strstr(url, "://")) != NULL) { - if (p < strchr(url, '/')) { - url = p + 3; - } + if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) { + url += sizeof("file://") - 1; } if (php_check_open_basedir(url TSRMLS_CC)) { @@ -1084,7 +1077,6 @@ static int php_plain_files_unlink(php_stream_wrapper *wrapper, const char *url, static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context TSRMLS_DC) { - char *p; int ret; if (!url_from || !url_to) { @@ -1102,16 +1094,12 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f } #endif - if ((p = strstr(url_from, "://")) != NULL) { - if (p < strchr(url_from, '/')) { - url_from = p + 3; - } + if (strncasecmp(url_from, "file://", sizeof("file://") - 1) == 0) { + url_from += sizeof("file://") - 1; } - if ((p = strstr(url_to, "://")) != NULL) { - if (p < strchr(url_to, '/')) { - url_to = p + 3; - } + if (strncasecmp(url_to, "file://", sizeof("file://") - 1) == 0) { + url_to += sizeof("file://") - 1; } if (php_check_open_basedir(url_from TSRMLS_CC) || php_check_open_basedir(url_to TSRMLS_CC)) { @@ -1176,10 +1164,8 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i int ret, recursive = options & PHP_STREAM_MKDIR_RECURSIVE; char *p; - if ((p = strstr(dir, "://")) != NULL) { - if (p < strchr(dir, '/')) { - dir = p + 3; - } + if (strncasecmp(dir, "file://", sizeof("file://") - 1) == 0) { + dir += sizeof("file://") - 1; } if (!recursive) { @@ -1261,6 +1247,10 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context TSRMLS_DC) { + if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) { + url += sizeof("file://") - 1; + } + #if PHP_WIN32 int url_len = strlen(url); #endif @@ -1289,7 +1279,6 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, i static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url, int option, void *value, php_stream_context *context TSRMLS_DC) { struct utimbuf *newtime; - char *p; #if !defined(WINDOWS) && !defined(NETWARE) uid_t uid; gid_t gid; @@ -1307,10 +1296,8 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url } #endif - if ((p = strstr(url, "://")) != NULL) { - if (p < strchr(url, '/')) { - url = p + 3; - } + if (strncasecmp(url, "file://", sizeof("file://") - 1) == 0) { + url += sizeof("file://") - 1; } if (php_check_open_basedir(url TSRMLS_CC)) { |