Bug #60183 [Opn->Csd]: Bug resulting in out of sync ftp responses
| From: | rasmus@php.net | Date: | Tue, 01 Nov 2011 15:16:14 +0000 |
| Subject: | Bug #60183 [Opn->Csd]: Bug resulting in out of sync ftp responses | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-164765@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60183&edit=1
ID: 60183
Updated by: rasmus@php.net
Reported by: bram at ebskamp dot me
Summary: Bug resulting in out of sync ftp responses
-Status: Open
+Status: Closed
Type: Bug
Package: FTP related
Operating System: All
PHP Version: 5.3.8
-Assigned To:
+Assigned To: rasmus
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in SVN.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2011-11-01 15:15:46] rasmus@php.net
Automatic comment from SVN on behalf of rasmus
Revision: http://svn.php.net/viewvc/?view=revision&revision=318649
Log: Fix bug 60183
------------------------------------------------------------------------
[2011-11-01 00:33:43] bram at ebskamp dot me
Description:
------------
Our servers make several hundred FTP-connections via PHP every day. About one
out of every thousand connections PHP throws a warning with a server-response
that is not even related to the executed command.
I've looked into the sourcecode and found a bug in the core of the ftp
extension. This bug appears whenever the ftp-server sends an extra response that
PHP was not expecting, resulting in the response-buffer permanently running out
of sync. Because of this, PHP will keep reading the wrong response lines (and
thus often receiving the wrong ftp status codes) and will report most ftp
commands as failed after this.
Looking at different complaints scatterred across the internet about receiving
unexpected responses from the PHP FTP extension after receiving 1 warning, this
bug has been bugging people for quite some time now. Some of the current ftp-
bugreports are a direct result of this bug.
Bugfix:
Clearing the 'extra' buffer object from the last response, before sending a new
command.
# diff -urN ftp_old.c ftp.c
--- ftp_old.c 2011-11-01 00:28:05.000000000 +0100
+++ ftp.c 2011-11-01 00:29:29.000000000 +0100
@@ -1122,6 +1122,9 @@
data = ftp->outbuf;
+ /* Clear the extra-lines buffer */
+ ftp->extra = NULL;
+
if (my_send(ftp, ftp->fd, data, size) != size) {
return 0;
}
Test script:
---------------
How to reproduce:
Let the ftp-server send an extra (unexpected) server response, or simulate one:
diff -urN ftp_old.c ftp.c
--- ftp_old.c 2011-11-01 00:28:05.000000000 +0100
+++ ftp.c 2011-11-01 01:07:34.000000000 +0100
@@ -1294,6 +1294,19 @@
#if HAVE_OPENSSL_EXT
}
#endif
+
+ /* Simulate an extra unexpected server command
+ in this case right after entering passive mode (code 227) */
+ char cmd[] = "200 OK.\n";
+ if (nr_bytes > 0)
+ {
+ if (!strncmp(buf, "227 ", 4))
+ {
+ strcat(ftp->inbuf, cmd);
+ nr_bytes += sizeof(cmd)-1;
+ }
+ }
+
return (nr_bytes);
}
/* }}} */
Expected result:
----------------
Expected result:
A warning.
Actual result:
--------------
Actual result:
A warning, but all commands followed by the last one are running out of
sync/failing. Also the warning thrown shows the wrong server response since the
buffer is running out of sync.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60183&edit=1