com php-src: fix ftp_login with ssl enabled: ext/ft p/ftp.c

From: Date: Wed, 11 Mar 2015 20:46:40 +0000
Subject: com php-src: fix ftp_login with ssl enabled: ext/ft p/ftp.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-85470@lists.php.net to get a copy of this message
Commit: d5f2b4b398f1307074b69f9e35fc6ed5f3a69b23 Author: Anatol Belski <ab@php.net> Wed, 11 Mar 2015 15:07:44 +0100 Parents: f1a47988b0bd35c44b08c1416b98e283fb3c3e77 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d5f2b4b398f1307074b69f9e35fc6ed5f3a69b23 Log: fix ftp_login with ssl enabled Changed paths: M ext/ftp/ftp.c Diff: diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 20f8cb9..3f01ea7 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -248,6 +248,8 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) #ifdef HAVE_FTP_SSL SSL_CTX *ctx = NULL; long ssl_ctx_options = SSL_OP_ALL; + int err, res; + zend_bool retry; #endif if (ftp == NULL) { return 0; @@ -298,13 +300,42 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass) SSL_set_fd(ftp->ssl_handle, ftp->fd); - /* TODO check SSL_get_error() and poll on failure */ - if (SSL_connect(ftp->ssl_handle) <= 0) { - php_error_docref(NULL, E_WARNING, "SSL/TLS handshake failed"); - SSL_shutdown(ftp->ssl_handle); - SSL_free(ftp->ssl_handle); - return 0; - } + do { + res = SSL_connect(ftp->ssl_handle); + err = SSL_get_error(ftp->ssl_handle, res); + + /* TODO check if handling other error codes would make sense */ + switch (err) { + case SSL_ERROR_NONE: + retry = 0; + break; + + case SSL_ERROR_WANT_READ: + case SSL_ERROR_WANT_WRITE: { + php_pollfd p; + int i; + + p.fd = ftp->fd; + p.events = (err == SSL_ERROR_WANT_READ) ? (POLLIN|POLLPRI) : POLLOUT; + p.revents = 0; + + i = php_poll2(&p, 1, 300); + + if (i > 0) { + retry = 1; + } else { + retry = 0; + } + } + break; + + default: + php_error_docref(NULL, E_WARNING, "SSL/TLS handshake failed"); + SSL_shutdown(ftp->ssl_handle); + SSL_free(ftp->ssl_handle); + return 0; + } + } while (retry); ftp->ssl_active = 1;

« previous php.cvs (#85470) next »