Skip to content

Commit 1e94f34

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Split off php_set_sock_blocking() and s.is_blocked to a separate function Fix missing checks against php_set_blocking() in xp_ssl.c
2 parents b14250a + 1863014 commit 1e94f34

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ PHP NEWS
4545
properties in traits). (nielsdos)
4646
. Fix leak of accel_globals->key. (nielsdos)
4747

48+
- OpenSSL:
49+
. Fix missing checks against php_set_blocking() in xp_ssl.c. (nielsdos)
50+
4851
- SPL:
4952
. Fixed bug GH-18421 (Integer overflow with large numbers in LimitIterator).
5053
(nielsdos)

ext/openssl/xp_ssl.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,15 @@ static int php_openssl_capture_peer_certs(php_stream *stream,
18971897
}
18981898
/* }}} */
18991899

1900+
static zend_result php_openssl_set_blocking(php_openssl_netstream_data_t *sslsock, int block)
1901+
{
1902+
zend_result result = php_set_sock_blocking(sslsock->s.socket, block);
1903+
if (EXPECTED(SUCCESS == result)) {
1904+
sslsock->s.is_blocked = block;
1905+
}
1906+
return result;
1907+
}
1908+
19001909
static int php_openssl_enable_crypto(php_stream *stream,
19011910
php_openssl_netstream_data_t *sslsock,
19021911
php_stream_xport_crypto_param *cparam) /* {{{ */
@@ -1925,8 +1934,7 @@ static int php_openssl_enable_crypto(php_stream *stream,
19251934
sslsock->state_set = 1;
19261935
}
19271936

1928-
if (SUCCESS == php_set_sock_blocking(sslsock->s.socket, 0)) {
1929-
sslsock->s.is_blocked = 0;
1937+
if (SUCCESS == php_openssl_set_blocking(sslsock, 0)) {
19301938
/* The following mode are added only if we are able to change socket
19311939
* to non blocking mode which is also used for read and write */
19321940
SSL_set_mode(sslsock->ssl_handle, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
@@ -1979,8 +1987,8 @@ static int php_openssl_enable_crypto(php_stream *stream,
19791987
}
19801988
} while (retry);
19811989

1982-
if (sslsock->s.is_blocked != blocked && SUCCESS == php_set_sock_blocking(sslsock->s.socket, blocked)) {
1983-
sslsock->s.is_blocked = blocked;
1990+
if (sslsock->s.is_blocked != blocked) {
1991+
php_openssl_set_blocking(sslsock, blocked);
19841992
}
19851993

19861994
if (n == 1) {
@@ -2063,8 +2071,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
20632071
timeout = &sslsock->s.timeout;
20642072
}
20652073

2066-
if (timeout && php_set_sock_blocking(sslsock->s.socket, 0) == SUCCESS) {
2067-
sslsock->s.is_blocked = 0;
2074+
if (timeout) {
2075+
php_openssl_set_blocking(sslsock, 0);
20682076
}
20692077

20702078
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
@@ -2088,8 +2096,7 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
20882096
if (php_openssl_compare_timeval(elapsed_time, *timeout) > 0 ) {
20892097
/* If the socket was originally blocking, set it back. */
20902098
if (began_blocked) {
2091-
php_set_sock_blocking(sslsock->s.socket, 1);
2092-
sslsock->s.is_blocked = 1;
2099+
php_openssl_set_blocking(sslsock, 1);
20932100
}
20942101
sslsock->s.timeout_event = 1;
20952102
return -1;
@@ -2184,8 +2191,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
21842191
}
21852192

21862193
/* And if we were originally supposed to be blocking, let's reset the socket to that. */
2187-
if (began_blocked && php_set_sock_blocking(sslsock->s.socket, 1) == SUCCESS) {
2188-
sslsock->s.is_blocked = 1;
2194+
if (began_blocked) {
2195+
php_openssl_set_blocking(sslsock, 1);
21892196
}
21902197

21912198
return 0 > nr_bytes ? 0 : nr_bytes;
@@ -2491,8 +2498,8 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
24912498
timeout = &tv;
24922499
}
24932500

2494-
if (timeout && php_set_sock_blocking(sslsock->s.socket, 0) == SUCCESS) {
2495-
sslsock->s.is_blocked = 0;
2501+
if (timeout) {
2502+
php_openssl_set_blocking(sslsock, 0);
24962503
}
24972504

24982505
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
@@ -2516,8 +2523,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
25162523
if (php_openssl_compare_timeval(elapsed_time, *timeout) > 0 ) {
25172524
/* If the socket was originally blocking, set it back. */
25182525
if (began_blocked) {
2519-
php_set_sock_blocking(sslsock->s.socket, 1);
2520-
sslsock->s.is_blocked = 1;
2526+
php_openssl_set_blocking(sslsock, 1);
25212527
}
25222528
sslsock->s.timeout_event = 1;
25232529
return PHP_STREAM_OPTION_RETURN_ERR;
@@ -2568,8 +2574,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
25682574

25692575
if (began_blocked && !sslsock->s.is_blocked) {
25702576
// Set it back to blocking
2571-
php_set_sock_blocking(sslsock->s.socket, 1);
2572-
sslsock->s.is_blocked = 1;
2577+
php_openssl_set_blocking(sslsock, 1);
25732578
}
25742579
} else {
25752580
#ifdef PHP_WIN32

0 commit comments

Comments
 (0)