cvs: php-src /ext/ftp ftp.c /ext/ftp/tests bug39458-2.phpt bug39458.phpt server.inc
| From: | Nuno Lopes | Date: | Fri, 01 Dec 2006 16:42:48 +0000 |
| Subject: | cvs: php-src /ext/ftp ftp.c /ext/ftp/tests bug39458-2.phpt bug39458.phpt server.inc | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-41817@lists.php.net to get a copy of this message | ||
nlopess Fri Dec 1 16:42:48 2006 UTC
Modified files:
/php-src/ext/ftp ftp.c
/php-src/ext/ftp/tests bug39458-2.phpt bug39458.phpt server.inc
Log:
MFB: fix #39458
http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/ftp.c?r1=1.117&r2=1.118&diff_format=u
Index: php-src/ext/ftp/ftp.c
diff -u php-src/ext/ftp/ftp.c:1.117 php-src/ext/ftp/ftp.c:1.118
--- php-src/ext/ftp/ftp.c:1.117 Sun Oct 8 13:34:22 2006
+++ php-src/ext/ftp/ftp.c Fri Dec 1 16:42:48 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: ftp.c,v 1.117 2006/10/08 13:34:22 bjori Exp $ */
+/* $Id: ftp.c,v 1.118 2006/12/01 16:42:48 nlopess Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -1614,10 +1614,15 @@
if (!ftp_putcmd(ftp, cmd, path)) {
goto bail;
}
- if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) {
+ if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125 &&
ftp->resp != 226)) {
goto bail;
}
+ /* some servers don't open a ftp-data connection if the directory is empty */
+ if (ftp->resp == 226) {
+ return ecalloc(1, sizeof(char**));
+ }
+
/* pull data buffer into tmpfile */
if ((data = data_accept(data, ftp TSRMLS_CC)) == NULL) {
goto bail;
http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/tests/bug39458-2.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/ftp/tests/bug39458-2.phpt
diff -u /dev/null php-src/ext/ftp/tests/bug39458-2.phpt:1.2
--- /dev/null Fri Dec 1 16:42:48 2006
+++ php-src/ext/ftp/tests/bug39458-2.phpt Fri Dec 1 16:42:48 2006
@@ -0,0 +1,36 @@
+--TEST--
+Bug #39458: ftp_nlist() returns false on empty directories (other server behaviour)
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+$bug39458=1;
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_login($ftp, 'user', 'pass'));
+
+var_dump(ftp_nlist($ftp, ''));
+var_dump(ftp_nlist($ftp, 'emptydir'));
+var_dump(ftp_nlist($ftp, 'bogusdir'));
+
+ftp_close($ftp);
+?>
+--EXPECT--
+bool(true)
+array(3) {
+ [0]=>
+ string(5) "file1"
+ [1]=>
+ string(5) "file1"
+ [2]=>
+ string(9) "file
+b0rk"
+}
+array(0) {
+}
+bool(false)
http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/tests/bug39458.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/ftp/tests/bug39458.phpt
diff -u /dev/null php-src/ext/ftp/tests/bug39458.phpt:1.2
--- /dev/null Fri Dec 1 16:42:48 2006
+++ php-src/ext/ftp/tests/bug39458.phpt Fri Dec 1 16:42:48 2006
@@ -0,0 +1,35 @@
+--TEST--
+Bug #39458: ftp_nlist() returns false on empty directories
+--SKIPIF--
+<?php
+require 'skipif.inc';
+?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+if (!$ftp) die("Couldn't connect to the server");
+
+var_dump(ftp_login($ftp, 'user', 'pass'));
+
+var_dump(ftp_nlist($ftp, ''));
+var_dump(ftp_nlist($ftp, 'emptydir'));
+var_dump(ftp_nlist($ftp, 'bogusdir'));
+
+ftp_close($ftp);
+?>
+--EXPECT--
+bool(true)
+array(3) {
+ [0]=>
+ string(5) "file1"
+ [1]=>
+ string(5) "file1"
+ [2]=>
+ string(9) "file
+b0rk"
+}
+array(0) {
+}
+bool(false)
http://cvs.php.net/viewvc.cgi/php-src/ext/ftp/tests/server.inc?r1=1.6&r2=1.7&diff_format=u
Index: php-src/ext/ftp/tests/server.inc
diff -u php-src/ext/ftp/tests/server.inc:1.6 php-src/ext/ftp/tests/server.inc:1.7
--- php-src/ext/ftp/tests/server.inc:1.6 Fri Nov 24 20:20:51 2006
+++ php-src/ext/ftp/tests/server.inc Fri Dec 1 16:42:48 2006
@@ -201,6 +201,33 @@
change_dir($m[1]);
fputs($s, "250 CWD command successful.\r\n");
+ } elseif (preg_match("~^NLST(?: ([A-Za-z./]+))?\r\n$~", $buf, $m)) {
+
+ if (isset($m[1]) && $m[1] === 'bogusdir') {
+ fputs($s, "250 $m[1]: No such file or directory\r\n");
+ continue;
+ }
+
+ // there are some servers that don't open the ftp-data socket if there's nothing to
send
+ if (isset($bug39458) && isset($m[1]) && $m[1] === 'emptydir') {
+ fputs($s, "226 Transfer complete.\r\n");
+ continue;
+ }
+
+ fputs($s, "150 File status okay; about to open data connection\r\n");
+
+ if (!$fs = stream_socket_client("tcp://$host:$port")) {
+ fputs($s, "425 Can't open data connection\r\n");
+ continue;
+ }
+
+ if (empty($m[1]) || $m[1] !== 'emptydir') {
+ fputs($fs, "file1\r\nfile1\r\nfile\nb0rk\r\n");
+ }
+
+ fputs($s, "226 Closing data Connection.\r\n");
+ fclose($fs);
+
} elseif (preg_match("~^MKD ([A-Za-z./]+)\r\n$~", $buf, $m)) {
if (isset($bug7216)) {
fputs($s, "257 OK.\r\n");