From eef11e048dcc538a189d7a1af918572a4c683ee3 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Fri, 19 Sep 2025 12:37:27 +0200 Subject: [PATCH] Fix GH-19798: XP_SOCKET XP_SSL: Incorrect condition for Win This fixes incorrect type conversion and subsequent check for Windows where returned socket is not an int. It should be noted that this is not really an issue as previous int would get negative so the check should still work. The issue actually happens only in master (PHP 8.5) where refactoring has been done and the type changed. Closes GH-19881 --- NEWS | 5 +++++ ext/openssl/xp_ssl.c | 4 ++-- main/streams/xp_socket.c | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 27214db0b90..0ecf44b4c4c 100644 --- a/NEWS +++ b/NEWS @@ -70,6 +70,11 @@ PHP NEWS - Standard: . Fix shm corruption with coercion in options of unserialize(). (nielsdos) +- Streams: + . Fixed bug GH-19798: XP_SOCKET XP_SSL (Socket stream modules): Incorrect + condition for Win32/Win64. (Jakub Zelenka) + + - Tidy: . Fixed GH-19021 (improved tidyOptGetCategory detection). (arjendekorte, David Carlier, Peter Kokot) diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index a9f5e277e78..b05cb16ada3 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -2342,7 +2342,7 @@ static int php_openssl_sockop_stat(php_stream *stream, php_stream_statbuf *ssb) static inline int php_openssl_tcp_sockop_accept(php_stream *stream, php_openssl_netstream_data_t *sock, php_stream_xport_param *xparam STREAMS_DC) /* {{{ */ { - int clisock; + php_socket_t clisock; bool nodelay = 0; zval *tmpzval = NULL; @@ -2363,7 +2363,7 @@ static inline int php_openssl_tcp_sockop_accept(php_stream *stream, php_openssl_ &xparam->outputs.error_code, nodelay); - if (clisock >= 0) { + if (clisock != SOCK_ERR) { php_openssl_netstream_data_t *clisockdata = (php_openssl_netstream_data_t*) emalloc(sizeof(*clisockdata)); /* copy underlying tcp fields */ diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index ef07f5f4866..331b882753a 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -854,7 +854,7 @@ out: static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t *sock, php_stream_xport_param *xparam STREAMS_DC) { - int clisock; + php_socket_t clisock; bool nodelay = 0; zval *tmpzval = NULL; @@ -875,7 +875,7 @@ static inline int php_tcp_sockop_accept(php_stream *stream, php_netstream_data_t &xparam->outputs.error_code, nodelay); - if (clisock >= 0) { + if (clisock != SOCK_ERR) { php_netstream_data_t *clisockdata = (php_netstream_data_t*) emalloc(sizeof(*clisockdata)); memcpy(clisockdata, sock, sizeof(*clisockdata));