]> granicus.if.org Git - php/commitdiff
Merge branch 'PHP-5.6' into PHP-7.0
authorNikita Popov <nikic@php.net>
Sat, 13 Aug 2016 19:41:00 +0000 (21:41 +0200)
committerNikita Popov <nikic@php.net>
Sat, 13 Aug 2016 19:41:00 +0000 (21:41 +0200)
1  2 
NEWS
ext/ftp/ftp.c

diff --cc NEWS
index 9bea75ea297c44df26d208cc0435a1dacbe88ddd,ccafb639910d3a3e1d9534a3aef6892bc32a05c0..3582cce48c9eb762c773992a84b667c2d3495b75
--- 1/NEWS
--- 2/NEWS
+++ b/NEWS
@@@ -1,23 -1,15 +1,27 @@@
  PHP                                                                        NEWS
  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 -?? ??? 2016, PHP 5.6.26
 +?? ??? 2016 PHP 7.0.11
 +
 +- Core:
 +  . Fixed bug #72813 (Segfault with __get returned by ref). (Laruence)
 +  . Fixed bug #72767 (PHP Segfaults when trying to expand an infinite operator).
 +    (Nikita)
  
 -- MSSQL:
 -  . Fixed bug #72039 (Use of uninitialised value on mssql_guid_string). (Kalle)
+ - FTP:
+   . Fixed bug #70195 (Cannot upload file using ftp_put to FTPES with
+     require_ssl_reuse). (Benedict Singer)
 +- GD:
 +  . Fixed bug #72709 (imagesetstyle() causes OOB read for empty $styles). (cmb)
 +
 +- OCI8
 +  . Fixed invalid handle error with Implicit Result Sets. (Chris Jones)
 +  . Fixed bug #72524 (Binding null values triggers ORA-24816 error). (Chris Jones)
  
  - PDO:
 +  . Fixed bug #72788 (Invalid memory access when using persistent PDO
 +    connection). (Keyur)
 +  . Fixed bug #72791 (Memory leak in PDO persistent connection handling). (Keyur)
    . Fixed bug #60665 (call to empty() on NULL result using PDO::FETCH_LAZY
      returns false). (cmb)
  
diff --cc ext/ftp/ftp.c
index b3548e70da43a679d91af0bd05a820f71424cb79,d2f726d038f099ca30b12c7da157185178be6d42..df8069144e95fe9352aef372632a6bd41642e321
@@@ -291,9 -290,12 +291,12 @@@ ftp_login(ftpbuf_t *ftp, const char *us
  #endif
                SSL_CTX_set_options(ctx, ssl_ctx_options);
  
+               /* allow SSL to re-use sessions */
+               SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_BOTH);
                ftp->ssl_handle = SSL_new(ctx);
                if (ftp->ssl_handle == NULL) {
 -                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to create the SSL handle");
 +                      php_error_docref(NULL, E_WARNING, "failed to create the SSL handle");
                        SSL_CTX_free(ctx);
                        return 0;
                }
@@@ -1635,11 -1496,10 +1638,11 @@@ data_accept(databuf_t *data, ftpbuf_t *
        php_sockaddr_storage addr;
        socklen_t                       size;
  
 -#if HAVE_OPENSSL_EXT
 +#ifdef HAVE_FTP_SSL
        SSL_CTX         *ctx;
-       zend_long ssl_ctx_options = SSL_OP_ALL;
+       SSL_SESSION *session;
 -      int result;
 +      int err, res;
 +      zend_bool retry;
  #endif
  
        if (data->fd != -1) {
@@@ -1660,21 -1520,15 +1663,15 @@@ data_accepted
  
        /* now enable ssl if we need to */
        if (ftp->use_ssl && ftp->use_ssl_for_data) {
-               ctx = SSL_CTX_new(SSLv23_client_method());
+               ctx = SSL_get_SSL_CTX(ftp->ssl_handle);
                if (ctx == NULL) {
-                       php_error_docref(NULL, E_WARNING, "data_accept: failed to create the SSL context");
 -                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: failed to retreive the existing SSL context");
++                      php_error_docref(NULL, E_WARNING, "data_accept: failed to retreive the existing SSL context");
                        return 0;
                }
  
- #if OPENSSL_VERSION_NUMBER >= 0x0090605fL
-               ssl_ctx_options &= ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
- #endif
-               SSL_CTX_set_options(ctx, ssl_ctx_options);
                data->ssl_handle = SSL_new(ctx);
                if (data->ssl_handle == NULL) {
 -                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: failed to create the SSL handle");
 +                      php_error_docref(NULL, E_WARNING, "data_accept: failed to create the SSL handle");
-                       SSL_CTX_free(ctx);
                        return 0;
                }
  
                        SSL_copy_session_id(data->ssl_handle, ftp->ssl_handle);
                }
  
 -                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: failed to retreive the existing SSL session");
+               /* get the session from the control connection so we can re-use it */
+               session = SSL_get_session(ftp->ssl_handle);
+               if (session == NULL) {
 -              result = SSL_set_session(data->ssl_handle, session);
 -              if (result == 0) {
 -                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: failed to set the existing SSL session");
++                      php_error_docref(NULL, E_WARNING, "data_accept: failed to retreive the existing SSL session");
+                       SSL_free(data->ssl_handle);
+                       return 0;
+               }
+               /* and set it on the data connection */
 -              if (SSL_connect(data->ssl_handle) <= 0) {
 -                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: SSL/TLS handshake failed");
 -                      SSL_shutdown(data->ssl_handle);
 -                      SSL_free(data->ssl_handle);
 -                      return 0;
 -              }
++              res = SSL_set_session(data->ssl_handle, session);
++              if (res == 0) {
++                      php_error_docref(NULL, E_WARNING, "data_accept: failed to set the existing SSL session");
+                       SSL_free(data->ssl_handle);
+                       return 0;
+               }
 +              do {
 +                      res = SSL_connect(data->ssl_handle);
 +                      err = SSL_get_error(data->ssl_handle, res);
 +
 +                      switch (err) {
 +                              case SSL_ERROR_NONE:
 +                                      retry = 0;
 +                                      break;
 +
 +                              case SSL_ERROR_ZERO_RETURN:
 +                                      retry = 0;
 +                                      SSL_shutdown(data->ssl_handle);
 +                                      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);
 +
 +                                              retry = i > 0;
 +                                      }
 +                                      break;
 +
 +                              default:
 +                                      php_error_docref(NULL, E_WARNING, "data_accept: SSL/TLS handshake failed");
 +                                      SSL_shutdown(data->ssl_handle);
 +                                      SSL_free(data->ssl_handle);
 +                                      return 0;
 +                      }
 +              } while (retry);
  
                data->ssl_active = 1;
        }
@@@ -1743,12 -1582,9 +1755,9 @@@ data_close(ftpbuf_t *ftp, databuf_t *da
                return NULL;
        }
        if (data->listener != -1) {
 -#if HAVE_OPENSSL_EXT
 +#ifdef HAVE_FTP_SSL
                if (data->ssl_active) {
-                       ctx = SSL_get_SSL_CTX(data->ssl_handle);
-                       SSL_CTX_free(ctx);
+                       /* don't free the data context, it's the same as the control */
                        SSL_shutdown(data->ssl_handle);
                        SSL_free(data->ssl_handle);
                        data->ssl_active = 0;
                closesocket(data->listener);
        }
        if (data->fd != -1) {
 -#if HAVE_OPENSSL_EXT
 +#ifdef HAVE_FTP_SSL
                if (data->ssl_active) {
-                       ctx = SSL_get_SSL_CTX(data->ssl_handle);
-                       SSL_CTX_free(ctx);
+                       /* don't free the data context, it's the same as the control */
                        SSL_shutdown(data->ssl_handle);
                        SSL_free(data->ssl_handle);
                        data->ssl_active = 0;