Skip to content

Commit 1ee4182

Browse files
authored
Check stream context is null (swoole#4016)
1 parent d0a9d10 commit 1ee4182

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

ext-src/swoole_runtime.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,9 +761,12 @@ static int socket_enable_crypto(php_stream *stream, Socket *sock, php_stream_xpo
761761
return sock->ssl_shutdown() ? 0 : -1;
762762
}
763763

764-
zval *val = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "ssl", "capture_peer_cert");
765-
if (val && zend_is_true(val)) {
766-
return php_openssl_capture_peer_certs(stream, sock) ? 0 : -1;
764+
php_stream_context *context = PHP_STREAM_CONTEXT(stream);
765+
if (context) {
766+
zval *val = php_stream_context_get_option(context, "ssl", "capture_peer_cert");
767+
if (val && zend_is_true(val)) {
768+
return php_openssl_capture_peer_certs(stream, sock) ? 0 : -1;
769+
}
767770
}
768771

769772
return 0;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
swoole_runtime: stream context pass null
3+
--SKIPIF--
4+
<?php require __DIR__ . '/../include/skipif.inc'; ?>
5+
--FILE--
6+
<?php
7+
require __DIR__ . '/../include/bootstrap.php';
8+
9+
swoole\runtime::enableCoroutine();
10+
go(function() {
11+
//This function internal send null stream context parameter to `php_stream_open_wrapper_ex`
12+
$md5 = md5_file('https://www.baidu.com');
13+
var_dump(!empty($md5));
14+
});
15+
swoole_event_wait();
16+
17+
?>
18+
--EXPECT--
19+
bool(true)

0 commit comments

Comments
 (0)