com php-src: Fix bug #77680: Correctly implement recursive mkdir on FTP stream: NEWS ext/ftp/tests/server.inc ext/standard/ftp_fopen _wrapper.c
ext/standard/tests/streams/bug77680 .phpt
| From: | Nikita Popov | Date: | Mon, 25 Mar 2019 16:43:46 +0000 |
| Subject: | com php-src: Fix bug #77680: Correctly implement recursive mkdir on FTP stream: NEWS ext/ftp/tests/server.inc ext/standard/ftp_fopen _wrapper.c ext/standard/tests/streams/bug77680 .phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-105332@lists.php.net to get a copy of this message | ||
Commit: ec2ecb7e12b96f8f95af2885d173a0d46c88e190
Author: Vlad Temian <vladtemian@gmail.com> Tue, 19 Mar 2019 18:36:45 +0200
Committer: Nikita Popov <nikita.ppv@gmail.com> Mon, 25 Mar 2019 17:43:46 +0100
Parents: 85095dfd0956bc09f5157211948c40cfa2859d27
Branches: PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ec2ecb7e12b96f8f95af2885d173a0d46c88e190
Log:
Fix bug #77680: Correctly implement recursive mkdir on FTP stream
If the root directory was missing, an extra CWD without arguments was
made. Also, the MKD contained an empty string.
Now the CWD will use / and MKDs will be issued starting from the root
directory.
Bugs:
https://bugs.php.net/77680
Changed paths:
M NEWS
M ext/ftp/tests/server.inc
M ext/standard/ftp_fopen_wrapper.c
A ext/standard/tests/streams/bug77680.phpt
Diff:
diff --git a/NEWS b/NEWS
index 8165400...52edd49 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,7 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2019, PHP 7.2.18
-- interbase:
+- Interbase:
. Fixed bug #72175 (Impossibility of creating multiple connections to
Interbase with php 7.x). (Nikita)
@@ -12,6 +12,10 @@ PHP NEWS
- Reflection:
. Fixed bug #77772 (ReflectionClass::getMethods(null) doesn't work). (Nikita)
+- Standard:
+ . Fixed bug #77680 (recursive mkdir on ftp stream wrapper is incorrect).
+ (Vlad Temian)
+
04 Apr 2019, PHP 7.2.17
- Core:
diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc
index 67531de..6e360c6 100644
--- a/ext/ftp/tests/server.inc
+++ b/ext/ftp/tests/server.inc
@@ -289,8 +289,13 @@ if ($pid) {
}
}elseif (preg_match("~^CWD ([A-Za-z./]+)\r\n$~", $buf, $m)) {
- change_dir($m[1]);
- fputs($s, "250 CWD command successful.\r\n");
+ if (isset($bug77680)) {
+ fputs($s, "550 Directory change to $m[1] failed: file does not exist\r\n");
+ var_dump($buf);
+ } else {
+ change_dir($m[1]);
+ fputs($s, "250 CWD command successful.\r\n");
+ }
} elseif (preg_match("~^NLST(?: ([A-Za-z../]+))?\r\n$~", $buf, $m)) {
@@ -332,6 +337,9 @@ if ($pid) {
if (isset($bug7216)) {
fputs($s, "257 OK.\r\n");
} else {
+ if (isset($bug77680)) {
+ var_dump($buf);
+ }
fputs($s, "257 \"/path/to/ftproot$cwd$m[1]\" created.\r\n");
}
diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c
index 37b754a...e23ffee 100644
--- a/ext/standard/ftp_fopen_wrapper.c
+++ b/ext/standard/ftp_fopen_wrapper.c
@@ -1070,41 +1070,40 @@ static int php_stream_ftp_mkdir(php_stream_wrapper *wrapper, const char
*url, in
/* find a top level directory we need to create */
while ((p = strrchr(buf, '/'))) {
- *p = '\0';
- php_stream_printf(stream, "CWD %s\r\n", buf);
+ *p = '\0';
+ php_stream_printf(stream, "CWD %s\r\n", strlen(buf) ? buf : "/");
result = GET_FTP_RESULT(stream);
if (result >= 200 && result <= 299) {
*p = '/';
break;
}
- }
- if (p == buf) {
- php_stream_printf(stream, "MKD %s\r\n", resource->path);
- result = GET_FTP_RESULT(stream);
- } else {
- php_stream_printf(stream, "MKD %s\r\n", buf);
- result = GET_FTP_RESULT(stream);
- if (result >= 200 && result <= 299) {
- if (!p) {
- p = buf;
- }
- /* create any needed directories if the creation of the 1st directory worked */
- while (++p != e) {
- if (*p == '\0' && *(p + 1) != '\0') {
- *p = '/';
- php_stream_printf(stream, "MKD %s\r\n", buf);
- result = GET_FTP_RESULT(stream);
- if (result < 200 || result > 299) {
- if (options & REPORT_ERRORS) {
- php_error_docref(NULL, E_WARNING, "%s", tmp_line);
- }
- break;
+ }
+
+ php_stream_printf(stream, "MKD %s\r\n", strlen(buf) ? buf : "/");
+ result = GET_FTP_RESULT(stream);
+
+ if (result >= 200 && result <= 299) {
+ if (!p) {
+ p = buf;
+ }
+ /* create any needed directories if the creation of the 1st directory worked */
+ while (p != e) {
+ if (*p == '\0' && *(p + 1) != '\0') {
+ *p = '/';
+ php_stream_printf(stream, "MKD %s\r\n", buf);
+ result = GET_FTP_RESULT(stream);
+ if (result < 200 || result > 299) {
+ if (options & REPORT_ERRORS) {
+ php_error_docref(NULL, E_WARNING, "%s", tmp_line);
}
+ break;
}
}
+ ++p;
}
}
- efree(buf);
+
+ efree(buf);
}
php_url_free(resource);
diff --git a/ext/standard/tests/streams/bug77680.phpt b/ext/standard/tests/streams/bug77680.phpt
new file mode 100644
index 0000000..8537bd4
--- /dev/null
+++ b/ext/standard/tests/streams/bug77680.phpt
@@ -0,0 +1,36 @@
+--TEST--
+Recursive mkdir() on ftp should create missing directories.
+--SKIPIF--
+<?php
+if (array_search('ftp',stream_get_wrappers()) === FALSE) die("skip ftp wrapper not
available.");
+if (!function_exists('pcntl_fork')) die("skip pcntl_fork() not available.");
+?>
+--FILE--
+<?php
+$bug77680=1;
+
+require __DIR__ . "/../../../ftp/tests/server.inc";
+
+$path = "ftp://localhost:" .
$port."/one/two/three/";
+mkdir($path, 0755, true);
+
+?>
+==DONE==
+--EXPECTF--
+string(20) "CWD /one/two/three
+"
+string(14) "CWD /one/two
+"
+string(10) "CWD /one
+"
+string(7) "CWD /
+"
+string(7) "MKD /
+"
+string(10) "MKD /one
+"
+string(14) "MKD /one/two
+"
+string(20) "MKD /one/two/three
+"
+==DONE==