Skip to content

Commit dd9aac9

Browse files
committed
Fix Issue #59 segfault on null passed as handle to uv_stdio_new
1 parent 73a295a commit dd9aac9

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

php_uv.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4908,11 +4908,10 @@ PHP_FUNCTION(uv_stdio_new)
49084908
return;
49094909
}
49104910

4911-
stdio = (php_uv_stdio_t*)emalloc(sizeof(php_uv_stdio_t));
4912-
stdio->flags = flags;
4913-
stdio->stream = NULL;
4914-
4915-
if (Z_TYPE_P(handle) == IS_LONG) {
4911+
if(Z_TYPE_P(handle) == IS_NULL) {
4912+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "passed unexpected resource");
4913+
RETURN_FALSE;
4914+
} else if (Z_TYPE_P(handle) == IS_LONG) {
49164915
fd = Z_LVAL_P(handle);
49174916
} else if (Z_TYPE_P(handle) == IS_RESOURCE) {
49184917
if (ZEND_FETCH_RESOURCE_NO_RETURN(stream, php_stream*, &handle, -1, NULL, php_file_le_stream())) {
@@ -4929,7 +4928,10 @@ PHP_FUNCTION(uv_stdio_new)
49294928
}
49304929
}
49314930

4932-
4931+
stdio = (php_uv_stdio_t*)emalloc(sizeof(php_uv_stdio_t));
4932+
stdio->flags = flags;
4933+
stdio->stream = NULL;
4934+
49334935
stdio->fd = fd;
49344936

49354937
if (Z_TYPE_P(handle) == IS_RESOURCE) {

tests/800-uv_spawn-issue59.phpt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--TEST--
2+
Test uv_spawn doesn't cause segfault #56
3+
--FILE--
4+
<?php
5+
6+
$ioRead = uv_stdio_new(null, Uv::CREATE_PIPE | Uv::INHERIT_STREAM);
7+
8+
--EXPECTF--
9+
Warning: uv_stdio_new(): passed unexpected resource in %s on line %d

0 commit comments

Comments
 (0)