Skip to content

Fix #78374: Warning when closing FTPS connection after FTP_PUT #7362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ext/ftp/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1582,14 +1582,15 @@ my_recv(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
/* {{{ data_available
*/
int
data_available(ftpbuf_t *ftp, php_socket_t s)
data_available(ftpbuf_t *ftp, php_socket_t s, zend_bool ignore_timeout)
{
int n;

n = php_pollfd_for_ms(s, PHP_POLLREADABLE, 1000);
if (n < 1) {
char buf[256];
if (n == 0) {
if (ignore_timeout) return 0;
#ifdef PHP_WIN32
_set_errno(ETIMEDOUT);
#else
Expand Down Expand Up @@ -1919,7 +1920,7 @@ static void ftp_ssl_shutdown(ftpbuf_t *ftp, php_socket_t fd, SSL *ssl_handle) {
done = 0;
}

while (!done && data_available(ftp, fd)) {
while (!done && data_available(ftp, fd, 1)) {
ERR_clear_error();
nread = SSL_read(ssl_handle, buf, sizeof(buf));
if (nread <= 0) {
Expand Down Expand Up @@ -2174,7 +2175,7 @@ ftp_nb_continue_read(ftpbuf_t *ftp)
data = ftp->data;

/* check if there is already more data */
if (!data_available(ftp, data->fd)) {
if (!data_available(ftp, data->fd, 0)) {
return PHP_FTP_MOREDATA;
}

Expand Down
24 changes: 24 additions & 0 deletions ext/ftp/tests/bug78374.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Bug #78374 (Warning when closing FTPS connection after FTP_PUT)
--SKIPIF--
<?php
$ssl = 1;
require 'skipif.inc';
if (!function_exists("ftp_ssl_connect")) die("skip ftp_ssl is disabled");
?>
--FILE--
<?php
$ssl = 1;
require 'server.inc';

$ftp = ftp_ssl_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_put($ftp, basename(__FILE__), __FILE__, FTP_ASCII));
var_dump(ftp_close($ftp));
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
4 changes: 4 additions & 0 deletions ext/ftp/tests/server.inc
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ if ($pid) {
continue;
}

if ((!empty($ssl)) && (!stream_socket_enable_crypto($fs, true, STREAM_CRYPTO_METHOD_TLS_SERVER, $s))) {
die("SSLv23 handshake failed.\n");
}

$data = stream_get_contents($fs);
$orig = file_get_contents(dirname(__FILE__).'/'.$m[1]);

Expand Down