Skip to content

Handle bindto error #5903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ext/standard/tests/network/bindto.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Test invalid bindto
--FILE--
<?php
$ctx = stream_context_create([
'socket' => [
'bindto' => 'invalid',
],
]);
$fp = stream_socket_client(
'tcp://www.' . str_repeat('x', 100) . '.com:80',
$errno, $errstr, 30, STREAM_CLIENT_CONNECT, $ctx
);
?>
--EXPECTF--
Warning: stream_socket_client(): Unable to connect to tcp://%s:80 (Failed to parse address "invalid") in %s on line %d
4 changes: 4 additions & 0 deletions main/streams/xp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,10 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
return -1;
}
bindto = parse_ip_address_ex(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text);
if (bindto == NULL) {
efree(host);
return -1;
}
}

#ifdef SO_BROADCAST
Expand Down