com php-src: Merge branch 'PHP-5.6': ext/openssl/xp_ssl.c
| From: | rdlowrey@php.net | Date: | Mon, 09 Feb 2015 20:14:47 +0000 |
| Subject: | com php-src: Merge branch 'PHP-5.6': ext/openssl/xp_ssl.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-84760@lists.php.net to get a copy of this message | ||
Commit: 712712e8d69b48d4c2c7a2e6da6d01bd53286e0b
Author: Daniel Lowrey <rdlowrey@php.net> Mon, 9 Feb 2015 15:14:47 -0500
Parents: f0d9d1828b694ee3df3bd2d4b6f14933f641bd98 fb2314798e28b4970cb35497ebc615dffc48d930
Branches: master
Link: http://git.php.net/?p=php-src..git;a=commitdiff;h=712712e8d69b48d4c2c7a2e6da6d01bd53286e0b
Log:
Merge branch 'PHP-5.6'
Conflicts:
ext/openssl/xp_ssl.c
Changed paths:
MM ext/openssl/xp_ssl.c
Diff:
diff --cc ext/openssl/xp_ssl.c
index e708419,70ec459..2008c11
--- a/ext/openssl/xp_ssl.c
+++ b/ext/openssl/xp_ssl.c
@@@ -1736,15 -1765,15 +1736,15 @@@ static int php_openssl_enable_crypto(ph
return -1;
}
- static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count) /* {{{
*/
-static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)/* {{{
*/
++static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count) /* {{{ */
{
- return php_openssl_sockop_io( 0, stream, (char*)buf, count );
- return php_openssl_sockop_io(1, stream, buf, count TSRMLS_CC);
++ return php_openssl_sockop_io( 1, stream, buf, count );
}
/* }}} */
- static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count) /* {{{ */
-static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count
TSRMLS_DC) /* {{{ */
++static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count) /* {{{
*/
{
- return php_openssl_sockop_io( 1, stream, buf, count );
- return php_openssl_sockop_io(0, stream, (char*)buf, count TSRMLS_CC);
++ return php_openssl_sockop_io( 0, stream, (char*)buf, count );
}
/* }}} */
@@@ -1762,19 -1792,13 +1762,19 @@@ static size_t php_openssl_sockop_io(in
/* Only do this if SSL is active. */
if (sslsock->ssl_active) {
int retry = 1;
- struct timeval start_time,
- *timeout;
- int blocked = sslsock->s.is_blocked,
- has_timeout = 0;
+ struct timeval start_time;
+ struct timeval *timeout;
+ int blocked = sslsock->s.is_blocked;
+ int has_timeout = 0;
+ int nr_bytes = 0;
+
+ /* prevent overflow in openssl */
+ if (count > INT_MAX) {
+ count = INT_MAX;
+ }
/* Begin by making the socket non-blocking. This allows us to check the timeout. */
- if (SUCCESS == php_set_sock_blocking(sslsock->s.socket, 0 TSRMLS_CC)) {
+ if (SUCCESS == php_set_sock_blocking(sslsock->s.socket, 0)) {
sslsock->s.is_blocked = 0;
}
@@@ -1811,17 -1835,17 +1811,17 @@@
/* Now, do the IO operation. Don't block if we can't complete... */
if (read) {
- nr_bytes = SSL_read(sslsock->ssl_handle, buf, count);
+ nr_bytes = SSL_read(sslsock->ssl_handle, buf, (int)count);
-
+
if (sslsock->reneg && sslsock->reneg->should_close) {
/* renegotiation rate limiting triggered */
- php_stream_xport_shutdown(stream, (stream_shutdown_t)SHUT_RDWR TSRMLS_CC);
+ php_stream_xport_shutdown(stream, (stream_shutdown_t)SHUT_RDWR);
nr_bytes = 0;
stream->eof = 1;
- break;
+ break;
}
} else {
- nr_bytes = SSL_write(sslsock->ssl_handle, buf, count);
+ nr_bytes = SSL_write(sslsock->ssl_handle, buf, (int)count);
}
/* Now, how much time until we time out? */
@@@ -1840,15 -1864,15 +1840,15 @@@
if (errno == EAGAIN && err == SSL_ERROR_WANT_READ && read) {
retry = 1;
}
- if (errno == EAGAIN && SSL_ERROR_WANT_WRITE && read == 0) {
+ if (errno == EAGAIN && SSL_ERROR_WANT_WRITE && read == 0) {
retry = 1;
}
-
+
/* Also, on reads, we may get this condition on an EOF. We should check properly. */
if (read) {
- stream->eof = (retry == 0 && errno != EAGAIN &&
!SSL_pending(sslsock->ssl_handle));
+ stream->eof = (retry == 0 && errno != EAGAIN &&
!SSL_pending(sslsock->ssl_handle));
}
-
+
/* Now, if we have to wait some time, and we're supposed to be blocking, wait for the
socket to become
* available. Now, php_pollfd_for uses select to wait up to our time_left value only...
*/
@@@ -1863,15 -1887,14 +1863,15 @@@
}
} else {
/* Else, if we got bytes back, check for possible errors. */
-- int err = SSL_get_error(sslsock->ssl_handle, nr_bytes );
++ int err = SSL_get_error(sslsock->ssl_handle, nr_bytes);
/* If we didn't get any error, then let's return it to PHP. */
- if (err == SSL_ERROR_NONE)
- break;
+ if (err == SSL_ERROR_NONE) {
+ break;
+ }
/* Otherwise, we need to wait again (up to time_left or we get an error) */
- if (blocked)
+ if (blocked) {
if (read) {
php_pollfd_for(sslsock->s.socket, (err == SSL_ERROR_WANT_WRITE) ?
(POLLOUT|POLLPRI) : (POLLIN|POLLPRI), has_timeout ? &left_time : NULL);
@@@ -1879,38 -1902,37 +1879,38 @@@
php_pollfd_for(sslsock->s.socket, (err == SSL_ERROR_WANT_READ) ?
(POLLIN|POLLPRI) : (POLLOUT|POLLPRI), has_timeout ? &left_time : NULL);
}
+ }
}
- /* Finally, we keep going until we got data, and an SSL_ERROR_NONE, unless we had an error. */
+
+ /* Finally, we keep going until we got data, and an SSL_ERROR_NONE, unless we had an error.
*/
} while (retry);
-
+
/* Tell PHP if we read / wrote bytes. */
if (nr_bytes > 0) {
- php_stream_notify_progress_increment(stream->context, nr_bytes, 0);
+ php_stream_notify_progress_increment(PHP_STREAM_CONTEXT(stream), nr_bytes, 0);
}
/* And if we were originally supposed to be blocking, let's reset the socket to that. */
if (blocked) {
- php_set_sock_blocking(sslsock->s.socket, 1 TSRMLS_CC);
+ php_set_sock_blocking(sslsock->s.socket, 1);
- sslsock->s.is_blocked = 1;
+ sslsock->s.is_blocked = 1;
}
+
+ return 0 > nr_bytes ? 0 : nr_bytes;
} else {
+ size_t nr_bytes = 0;
+
/*
- * This block is if we had no timeout... We will just sit and wait forever on the IO
operation.
- * This block is if we had no timeout... We will just sit and wait forever on the IO operation.
++ * This block is if we had no timeout... We will just sit and wait forever on the IO
operation.
*/
if (read) {
- nr_bytes = php_stream_socket_ops.read(stream, buf, count TSRMLS_CC);
+ nr_bytes = php_stream_socket_ops.read(stream, buf, count);
} else {
- nr_bytes = php_stream_socket_ops.write(stream, buf, count TSRMLS_CC);
+ nr_bytes = php_stream_socket_ops.write(stream, buf, count);
}
- }
- /* PHP doesn't expect a negative return. */
- if (nr_bytes < 0) {
- nr_bytes = 0;
+ return nr_bytes;
}
-
- return nr_bytes;
}
/* }}} */
@@@ -2253,14 -2272,14 +2253,14 @@@ php_stream_ops php_openssl_socket_ops
php_openssl_sockop_set_option,
};
-static long get_crypto_method(php_stream_context *ctx, long crypto_method)
+static zend_long get_crypto_method(php_stream_context *ctx, zend_long crypto_method)
{
- zval **val;
+ zval *val;
- if (ctx && php_stream_context_get_option(ctx, "ssl", "crypto_method",
&val) == SUCCESS) {
+ if (ctx && (val = php_stream_context_get_option(ctx, "ssl",
"crypto_method")) != NULL) {
convert_to_long_ex(val);
- crypto_method = (long)Z_LVAL_PP(val);
+ crypto_method = (zend_long)Z_LVAL_P(val);
- crypto_method |= STREAM_CRYPTO_IS_CLIENT;
+ crypto_method |= STREAM_CRYPTO_IS_CLIENT;
}
return crypto_method;
@@@ -2397,4 -2412,4 +2397,4 @@@ php_stream *php_openssl_ssl_socket_fact
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
-- */
++ */