Skip to content

Commit 0b8c83f

Browse files
committed
Handle bindto error
Closes GH-5903.
1 parent 9a744c6 commit 0b8c83f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Test invalid bindto
3+
--FILE--
4+
<?php
5+
$ctx = stream_context_create([
6+
'socket' => [
7+
'bindto' => 'invalid',
8+
],
9+
]);
10+
$fp = stream_socket_client(
11+
'tcp://www.' . str_repeat('x', 100) . '.com:80',
12+
$errno, $errstr, 30, STREAM_CLIENT_CONNECT, $ctx
13+
);
14+
?>
15+
--EXPECTF--
16+
Warning: stream_socket_client(): Unable to connect to tcp://%s:80 (Failed to parse address "invalid") in %s on line %d

main/streams/xp_socket.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
744744
return -1;
745745
}
746746
bindto = parse_ip_address_ex(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text);
747+
if (bindto == NULL) {
748+
efree(host);
749+
return -1;
750+
}
747751
}
748752

749753
#ifdef SO_BROADCAST

0 commit comments

Comments
 (0)