chobie / php-uv

libuv php extension
185 stars 21 forks source link

Segfault while spawning a new process with uv_spawn on PHP 5.5.9 #56

Open gplanchat opened 10 years ago

gplanchat commented 10 years ago

Hello,

The following code produces a segmentation fault on Ubuntu 14.04 LTS with kernel version 3.13.0 and PHP 5.5.9 :

<?php

$ioRead = uv_stdio_new(null, Uv::CREATE_PIPE | Uv::INHERIT_STREAM);
$ioWrite = uv_stdio_new(null, Uv::CREATE_PIPE | Uv::INHERIT_STREAM);
$ioError = uv_stdio_new(null, Uv::CREATE_PIPE | Uv::INHERIT_STREAM);

$loop = uv_default_loop();
$command = 'ls';
$args = [];
$stdio = [
    0 => $ioRead,
    1 => $ioWrite,
    2 => $ioError
];
$cwd = getcwd();
$env = [];
$callback = function() {
    var_dump(func_get_args());
};
$flags = 0;
$options = [];

$process = uv_spawn($loop, $command, $args, $stdio, $cwd, $env, $callback, $flags, $options);

uv_run($loop);
PHP 5.5.9-1ubuntu4.3 (cli) (built: Jul  7 2014 16:36:58) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
uv
PHP libuv Extension

libuv Support => enabled
Version => 0.0.2
libuv Version => 0.10
http-parser Version => 2.2
steverhoades commented 10 years ago

Anyway you can see if this is fixed with #59 ? I was able to reproduce and fix a uv_spawn related issue with PHP 5.6.

steverhoades commented 10 years ago

Can confirm this still segfaults with #59.

steverhoades commented 10 years ago

@gplanchat I have updated the code to throw warnings when a pipe handle is not passed to uv_stdio_new. It appears the correct usage should be:

$ioReadPipe = uv_pipe_init($loop, true);
$ioWritePipe = uv_pipe_init($loop, true);
$ioErrorPipe = uv_pipe_init($loop, true);

$ioRead = uv_stdio_new($ioReadPipe, Uv::CREATE_PIPE | Uv::INHERIT_STREAM);
$ioWrite = uv_stdio_new($ioWritePipe, Uv::CREATE_PIPE | Uv::INHERIT_STREAM);
$ioError = uv_stdio_new($ioErrorPipe, Uv::CREATE_PIPE | Uv::INHERIT_STREAM);

Am i missing something here?

gplanchat commented 10 years ago

It would say yes, it is the logical path. It seems that you are trying to spawn a new process, but for the use of uv_spawn, isn't the pipes array created by the API?