Skip to content

Commit 4f984a2

Browse files
committed
Fixed bug #78775
Clear the OpenSSL error queue before performing SSL stream operations. As we don't control all code that could possibly be using OpenSSL, we can't rely on the error queue being empty.
1 parent e29922f commit 4f984a2

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ PHP NEWS
2626
non-ascii characters). (mhagstrand)
2727
. Fixed bug #78747 (OpCache corrupts custom extension result). (Nikita)
2828

29+
- OpenSSL:
30+
. Fixed bug #78775 (TLS issues from HTTP request affecting other encrypted
31+
connections). (Nikita)
32+
2933
- Reflection:
3034
. Fixed bug #78697 (ReflectionClass::ImplementsInterface - inaccurate error
3135
message with traits). (villfa)

ext/curl/tests/bug78775.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Bug #78775: TLS issues from HTTP request affecting other encrypted connections
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('curl')) die('skip Requires curl');
6+
if (getenv('SKIP_ONLINE_TESTS')) die('skip Online test');
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$sock = fsockopen("tls://google.com", 443);
12+
13+
var_dump($sock);
14+
15+
$handle = curl_init('https://self-signed.badssl.com/');
16+
curl_setopt_array(
17+
$handle,
18+
[
19+
CURLOPT_RETURNTRANSFER => true,
20+
CURLOPT_SSL_VERIFYPEER => true,
21+
]
22+
);
23+
24+
var_dump(curl_exec($handle));
25+
curl_close($handle);
26+
27+
fwrite($sock, "GET / HTTP/1.0\n\n");
28+
var_dump(fread($sock, 8));
29+
30+
?>
31+
--EXPECTF--
32+
resource(%d) of type (stream)
33+
bool(false)
34+
string(8) "HTTP/1.0"

ext/openssl/xp_ssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,7 @@ static int php_openssl_enable_crypto(php_stream *stream,
18731873
do {
18741874
struct timeval cur_time, elapsed_time;
18751875

1876+
ERR_clear_error();
18761877
if (sslsock->is_client) {
18771878
n = SSL_connect(sslsock->ssl_handle);
18781879
} else {
@@ -2045,6 +2046,7 @@ static size_t php_openssl_sockop_io(int read, php_stream *stream, char *buf, siz
20452046
}
20462047

20472048
/* Now, do the IO operation. Don't block if we can't complete... */
2049+
ERR_clear_error();
20482050
if (read) {
20492051
nr_bytes = SSL_read(sslsock->ssl_handle, buf, (int)count);
20502052

0 commit comments

Comments
 (0)