diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 31ec7dc7343a..fd0f295500b8 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -1874,7 +1874,7 @@ data_accept(databuf_t *data, ftpbuf_t *ftp) data->listener = -1; if (data->fd == -1) { - efree(data); + /* data is still owned by ftp->data, the caller's data_close() frees it */ return NULL; } diff --git a/ext/ftp/tests/ftp_get_data_accept_timeout.phpt b/ext/ftp/tests/ftp_get_data_accept_timeout.phpt new file mode 100644 index 000000000000..bf0ece9a3fa2 --- /dev/null +++ b/ext/ftp/tests/ftp_get_data_accept_timeout.phpt @@ -0,0 +1,39 @@ +--TEST-- +ftp_get()/ftp_nb_get() fail cleanly when the active data connection is never opened +--EXTENSIONS-- +ftp +pcntl +--FILE-- + +--CLEAN-- + +--EXPECTF-- +bool(true) +bool(true) + +Warning: ftp_get(): %s timed out in %s on line %d + +Warning: ftp_get(): File status okay; about to open data connection. in %s on line %d +bool(false) + +Warning: ftp_nb_get(): %s timed out in %s on line %d + +Warning: ftp_nb_get(): File status okay; about to open data connection. in %s on line %d +bool(true) diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index add8c3ae70ac..2d9697e4d35d 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -328,6 +328,11 @@ if ($pid) { break; } }elseif (preg_match('/^RETR ([\/]*[\w\h]+)/', $buf, $matches)) { + if ($matches[1] === "no_data_connection") { + // Never open the active data connection. + fputs($s, "150 File status okay; about to open data connection.\r\n"); + continue; + } if(!empty($pasv)){ ; }