php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77661 Connection succeeds despite invalid bind address
Submitted: 2019-02-24 13:07 UTC Modified: -
From: me at tati dot pro Assigned:
Status: Open Package: Sockets related
PHP Version: master-Git-2019-02-24 (Git) OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: me at tati dot pro
New email:
PHP Version: OS:

 

 [2019-02-24 13:07 UTC] me at tati dot pro
Description:
------------
If invalid bind address is specified with stream_socket_client, than connection still be successfull.

I working with 4g usb modems, which sometimes hangs and reboots (in this time network interface is not available, so i receiving error that bind fails).

Checking if interfaces is not available before creating socket working 99% times, but not 100%.

If i receive that error than i can close socket immediately, but syn/ack/rst sequence 'll be produced that is undesirable behavior.

My program should not work if binding fails, because routing 'll be incorrect in this case.

So i need the way to change behavior, like an additional stream option that 'll force connection error if bind fails.

https://github.com/php/php-src/blob/623911f993f39ebbe75abe2771fc89faf6b15b9b/main/network.c#L876

Test script:
---------------
$context = stream_context_create(array('socket'=>array('bindto'=>'1.2.3.4:5678')));

$stream = stream_socket_client('tcp://google.com:80', $errno, $errstr, 10, STREAM_CLIENT_CONNECT, $context);

var_dump($stream);

Expected result:
----------------
Connection should not be created.

Actual result:
--------------
PHP Warning:  stream_socket_client(): failed to bind to '1.2.3.4:5678', system said: Cannot assign requested address in /home/tatikoma/z.php on line 4
PHP Stack trace:
PHP   1. {main}() /home/tatikoma/z.php:0
PHP   2. stream_socket_client() /home/tatikoma/z.php:4
resource(5) of type (stream)

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC