hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

Bad error message on socket connection error: "Success."

Open woxxy opened this issue 12 years ago • 2 comments

On stream_socket_client, a permission error sets $errstr to Success. instead of Permission denied..

To reproduce:

  • Create a socket with bad permissions for the user running HHVM.

    I did this for mistake by leaving default 755 permissions on Redis and running HHVM as www-data.

  • Run the following script (mimicks predis connection via socket)

<?php
$flags = STREAM_CLIENT_CONNECT;
$uri = 'unix:///tmp/redis.sock';

$resource = @stream_socket_client($uri, $errno, $errstr, 5, $flags);

if (!$resource) {
        echo 'Error: '.$errstr;
        return;
}

echo 'No errors.';

Results as follows:

$ /opt/dev/hhvm/hphp/hhvm/hhvm socket.php
Error: Success.
$ php socket.php
Error: Permission denied.

HHVM compiled from master today:

$ /opt/dev/hhvm/hphp/hhvm/hhvm --version
HipHop VM 3.1.0-dev (rel)
Compiler: heads/master-0-g4a3734e95a457d4bd5e2642f3b27f834076d1d36
Repo schema: f2253816513825cba69200daf3e3e560015478f7
$ php -v
PHP 5.5.11 (cli) (built: Apr 25 2014 05:27:10)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

woxxy avatar May 03 '14 11:05 woxxy

In file hphp/runtime/ext/ext_socket.cpp#L1142 sock->getError() remains 0. sock->getLastError() seems to work. You can workaround it with this diff: https://gist.github.com/SiebelsTim/849fb97c4f46b8bab16a

However stream_socket_create raises a warning in php and no error in hhvm

SiebelsTim avatar May 03 '14 14:05 SiebelsTim

You can raise a warning with raise_warning. Can you send your diff as a PR?

ptarjan avatar May 14 '14 08:05 ptarjan