Skip to content

Commit e2b47d8

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: 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 63657df + 1e94f34 commit e2b47d8

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

ext/openssl/xp_ssl.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,15 @@ static int php_openssl_capture_peer_certs(php_stream *stream,
17761776
}
17771777
/* }}} */
17781778

1779+
static zend_result php_openssl_set_blocking(php_openssl_netstream_data_t *sslsock, int block)
1780+
{
1781+
zend_result result = php_set_sock_blocking(sslsock->s.socket, block);
1782+
if (EXPECTED(SUCCESS == result)) {
1783+
sslsock->s.is_blocked = block;
1784+
}
1785+
return result;
1786+
}
1787+
17791788
static int php_openssl_enable_crypto(php_stream *stream,
17801789
php_openssl_netstream_data_t *sslsock,
17811790
php_stream_xport_crypto_param *cparam) /* {{{ */
@@ -1804,8 +1813,7 @@ static int php_openssl_enable_crypto(php_stream *stream,
18041813
sslsock->state_set = 1;
18051814
}
18061815

1807-
if (SUCCESS == php_set_sock_blocking(sslsock->s.socket, 0)) {
1808-
sslsock->s.is_blocked = 0;
1816+
if (SUCCESS == php_openssl_set_blocking(sslsock, 0)) {
18091817
/* The following mode are added only if we are able to change socket
18101818
* to non blocking mode which is also used for read and write */
18111819
SSL_set_mode(sslsock->ssl_handle, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
@@ -1858,8 +1866,8 @@ static int php_openssl_enable_crypto(php_stream *stream,
18581866
}
18591867
} while (retry);
18601868

1861-
if (sslsock->s.is_blocked != blocked && SUCCESS == php_set_sock_blocking(sslsock->s.socket, blocked)) {
1862-
sslsock->s.is_blocked = blocked;
1869+
if (sslsock->s.is_blocked != blocked) {
1870+
php_openssl_set_blocking(sslsock, blocked);
18631871
}
18641872

18651873
if (n == 1) {
@@ -1942,8 +1950,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
19421950
timeout = &sslsock->s.timeout;
19431951
}
19441952

1945-
if (timeout && php_set_sock_blocking(sslsock->s.socket, 0) == SUCCESS) {
1946-
sslsock->s.is_blocked = 0;
1953+
if (timeout) {
1954+
php_openssl_set_blocking(sslsock, 0);
19471955
}
19481956

19491957
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
@@ -1967,8 +1975,7 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
19671975
if (php_openssl_compare_timeval(elapsed_time, *timeout) > 0 ) {
19681976
/* If the socket was originally blocking, set it back. */
19691977
if (began_blocked) {
1970-
php_set_sock_blocking(sslsock->s.socket, 1);
1971-
sslsock->s.is_blocked = 1;
1978+
php_openssl_set_blocking(sslsock, 1);
19721979
}
19731980
sslsock->s.timeout_event = 1;
19741981
return -1;
@@ -2063,8 +2070,8 @@ static ssize_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, si
20632070
}
20642071

20652072
/* And if we were originally supposed to be blocking, let's reset the socket to that. */
2066-
if (began_blocked && php_set_sock_blocking(sslsock->s.socket, 1) == SUCCESS) {
2067-
sslsock->s.is_blocked = 1;
2073+
if (began_blocked) {
2074+
php_openssl_set_blocking(sslsock, 1);
20682075
}
20692076

20702077
return 0 > nr_bytes ? 0 : nr_bytes;
@@ -2370,8 +2377,8 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
23702377
timeout = &tv;
23712378
}
23722379

2373-
if (timeout && php_set_sock_blocking(sslsock->s.socket, 0) == SUCCESS) {
2374-
sslsock->s.is_blocked = 0;
2380+
if (timeout) {
2381+
php_openssl_set_blocking(sslsock, 0);
23752382
}
23762383

23772384
if (!sslsock->s.is_blocked && timeout && (timeout->tv_sec > 0 || (timeout->tv_sec == 0 && timeout->tv_usec))) {
@@ -2395,8 +2402,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
23952402
if (php_openssl_compare_timeval(elapsed_time, *timeout) > 0 ) {
23962403
/* If the socket was originally blocking, set it back. */
23972404
if (began_blocked) {
2398-
php_set_sock_blocking(sslsock->s.socket, 1);
2399-
sslsock->s.is_blocked = 1;
2405+
php_openssl_set_blocking(sslsock, 1);
24002406
}
24012407
sslsock->s.timeout_event = 1;
24022408
return PHP_STREAM_OPTION_RETURN_ERR;
@@ -2447,8 +2453,7 @@ static int php_openssl_sockop_set_option(php_stream *stream, int option, int val
24472453

24482454
if (began_blocked && !sslsock->s.is_blocked) {
24492455
// Set it back to blocking
2450-
php_set_sock_blocking(sslsock->s.socket, 1);
2451-
sslsock->s.is_blocked = 1;
2456+
php_openssl_set_blocking(sslsock, 1);
24522457
}
24532458
} else {
24542459
#ifdef PHP_WIN32

0 commit comments

Comments
 (0)