diff options
| author | Ville Hukkamäki <vhu@iki.fi> | 2016-07-25 18:50:38 +0000 |
|---|---|---|
| committer | Nikita Popov <nikic@php.net> | 2016-07-27 15:55:47 +0200 |
| commit | cce457c68c3a15efafea3a30560c54f74f3f5ee1 (patch) | |
| tree | 3f556976a22f905829b46e12be8b0367aeda1cef /ext/standard/ftp_fopen_wrapper.c | |
| parent | 074b86d8451365c81d3ae76616fb4df1757ddc1f (diff) | |
| download | php-git-cce457c68c3a15efafea3a30560c54f74f3f5ee1.tar.gz | |
Fix bug #72667
Open data stream after receiving PASV reply, before sending the
main request.
Included test cases for opendir() with ftp:// and ftps:// wrappers.
Test cases re-use ext/ftp/tests/server.inc
Conflicts:
ext/standard/ftp_fopen_wrapper.c
Diffstat (limited to 'ext/standard/ftp_fopen_wrapper.c')
| -rw-r--r-- | ext/standard/ftp_fopen_wrapper.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c index 0260ca1eab..b7eeb5649e 100644 --- a/ext/standard/ftp_fopen_wrapper.c +++ b/ext/standard/ftp_fopen_wrapper.c @@ -716,6 +716,9 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat if (result > 299 || result < 200) goto opendir_errexit; + // tmp_line isn't relevant after the php_fopen_do_pasv(). + tmp_line[0] = '\0'; + /* set up the passive connection */ portno = php_fopen_do_pasv(stream, ip, sizeof(ip), &hoststart TSRMLS_CC); @@ -723,29 +726,17 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat goto opendir_errexit; } - php_stream_printf(stream TSRMLS_CC, "NLST %s\r\n", (resource->path != NULL ? resource->path : "/")); - /* open the data channel */ if (hoststart == NULL) { hoststart = resource->host; } + datastream = php_stream_sock_open_host(hoststart, portno, SOCK_STREAM, 0, 0); if (datastream == NULL) { goto opendir_errexit; } - result = GET_FTP_RESULT(stream); - if (result != 150 && result != 125) { - /* Could not retrieve or send the file - * this data will only be sent to us after connection on the data port was initiated. - */ - php_stream_close(datastream); - datastream = NULL; - goto opendir_errexit; - } - php_stream_context_set(datastream, context); - if (use_ssl_on_data && (php_stream_xport_crypto_setup(datastream, STREAM_CRYPTO_METHOD_SSLv23_CLIENT, NULL TSRMLS_CC) < 0 || php_stream_xport_crypto_enable(datastream, 1 TSRMLS_CC) < 0)) { @@ -753,6 +744,19 @@ php_stream * php_stream_ftp_opendir(php_stream_wrapper *wrapper, const char *pat php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to activate SSL mode"); php_stream_close(datastream); datastream = NULL; + goto opendir_errexit; + } + + + php_stream_printf(stream TSRMLS_CC, "NLST %s\r\n", (resource->path != NULL ? resource->path : "/")); + + result = GET_FTP_RESULT(stream); + if (result != 150 && result != 125) { + /* Could not retrieve or send the file + * this data will only be sent to us after connection on the data port was initiated. + */ + php_stream_close(datastream); + datastream = NULL; goto opendir_errexit; } |
