}
/* }}} */
-static zend_long php_get_crypto_method_ctx_flags(zend_long method_flags) /* {{{ */
+static int php_get_crypto_method_ctx_flags(int method_flags) /* {{{ */
{
- zend_long ssl_ctx_options = SSL_OP_ALL;
+ int ssl_ctx_options = SSL_OP_ALL;
#ifndef OPENSSL_NO_SSL2
if (!(method_flags & STREAM_CRYPTO_METHOD_SSLv2)) {
) /* {{{ */
{
const SSL_METHOD *method;
- long ssl_ctx_options;
- long method_flags;
+ int ssl_ctx_options;
+ int method_flags;
char *cipherlist = NULL;
zval *val;
static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, size_t count) /* {{{ */
{
php_openssl_netstream_data_t *sslsock = (php_openssl_netstream_data_t*)stream->abstract;
- int nr_bytes = 0;
/* Only do this if SSL is active. */
if (sslsock->ssl_active) {
*timeout;
int blocked = sslsock->s.is_blocked,
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)) {
/* 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 */
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? */
php_set_sock_blocking(sslsock->s.socket, 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.
*/
} else {
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;
}
/* }}} */
if (value == -1) {
if (sslsock->s.timeout.tv_sec == -1) {
- tv.tv_sec = FG(default_socket_timeout);
+#ifdef _WIN32
+ tv.tv_sec = (long)FG(default_socket_timeout);
+#else
+ tv.tv_sec = (time_t)FG(default_socket_timeout);
+#endif
tv.tv_usec = 0;
} else {
tv = sslsock->connect_timeout;
sslsock->s.is_blocked = 1;
/* this timeout is used by standard stream funcs, therefor it should use the default value */
+#ifdef _WIN32
sslsock->s.timeout.tv_sec = (long)FG(default_socket_timeout);
+#else
+ sslsock->s.timeout.tv_sec = (time_t)FG(default_socket_timeout);
+#endif
sslsock->s.timeout.tv_usec = 0;
/* use separate timeout for our private funcs */