php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76839 socket_recvfrom may return an invalid 'from' address on MacOS
Submitted: 2018-09-04 17:43 UTC Modified: 2018-12-26 19:22 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: michael at meyer dot io Assigned: ab (profile)
Status: Closed Package: Sockets related
PHP Version: 7.2.9 OS: macOS 10.14
Private report: No CVE-ID: None
 [2018-09-04 17:43 UTC] michael at meyer dot io
Description:
------------
On MacOS 10.14 w/PHP 7.2.9, socket_recvfrom is returning invalid 'from' addresses which have trailing garbage bytes at the end.

This makes it impossible to respond with socket_sendto unless you know what the correct 'from' address should be.

I created a pull request for this bug on GitHub: https://github.com/php/php-src/pull/3408

Test script:
---------------
<?php

for ($i = 0; $i < 10; $i++) {
    $senderSocketPath = '/tmp/' . substr(md5(rand()), 0, rand(8, 16)) . '.sock';
    $senderSocket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
    socket_bind($senderSocket, $senderSocketPath);

    $receiverSocketPath = '/tmp/' . substr(md5(rand()), 0, rand(8, 16)) . '.sock';
    $receiverSocket = socket_create(AF_UNIX, SOCK_DGRAM, 0);
    socket_bind($receiverSocket, $receiverSocketPath);

    // Send message from socket 1 to socket 2
    socket_sendto($senderSocket, 'Ping!', 5, 0, $receiverSocketPath);

    // Receive & respond to message on socket 2
    $from = '';
    $message = '';
    socket_recvfrom($receiverSocket, $message, 65535, 0, $from);
    echo "Received '$message'\n";

    // Respond to the sender using the 'from' address from socket_recvfrom
    socket_sendto($receiverSocket, 'Pong!', 5, 0, $from);
    echo "Responded to sender with 'Pong!'\n";

    socket_close($receiverSocket);
    unlink($receiverSocketPath);
    socket_close($senderSocket);
    unlink($senderSocketPath);
}

Expected result:
----------------
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'

Actual result:
--------------
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
PHP Warning:  socket_sendto(): unable to write to socket [2]: No such file or directory in <test script> on line 22

Warning: socket_sendto(): unable to write to socket [2]: No such file or directory in <test script> on line 22
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
PHP Warning:  socket_sendto(): unable to write to socket [2]: No such file or directory in <test script> on line 22

Warning: socket_sendto(): unable to write to socket [2]: No such file or directory in <test script> on line 22
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'
Received 'Ping!'
Responded to sender with 'Pong!'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-26 19:22 UTC] ab@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ab
 [2018-12-26 19:22 UTC] ab@php.net
The PR has been merged.

Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC