]> granicus.if.org Git - php/commitdiff
Fixed bug #72075 (Referencing socket resources breaks stream_select)
authorXinchen Hui <laruence@gmail.com>
Sat, 23 Apr 2016 04:20:53 +0000 (21:20 -0700)
committerXinchen Hui <laruence@gmail.com>
Sat, 23 Apr 2016 04:21:49 +0000 (21:21 -0700)
NEWS
ext/standard/streamsfuncs.c
ext/standard/tests/streams/bug72075.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 18e07793ecb61b412aba5a704bbf264428136e38..fc20ad4ac538517d069e1334c9a7cf612577e30d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,8 @@ PHP                                                                        NEWS
   . Fixed bug #68849 (bindValue is not using the right data type). (Anatol)
 
 - Standard:
+  . Fixed bug #72075 (Referencing socket resources breaks stream_select).
+    (Laruence)
   . Fixed bug #72031 (array_column() against an array of objects discards all
     values matching null). (Nikita)
 
index def1fb88d7b26660786b7e2319b6752f4e951376..0e5d0ce79e5b5d16f44704f984f52f7ea952565d 100644 (file)
@@ -613,6 +613,7 @@ static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, php_socket_t
                        the higher bits of a SOCKET variable uninitialized on systems with little endian. */
                php_socket_t this_fd;
 
+               ZVAL_DEREF(elem);
                php_stream_from_zval_no_verify(stream, elem);
                if (stream == NULL) {
                        continue;
@@ -652,6 +653,7 @@ static int stream_array_from_fd_set(zval *stream_array, fd_set *fds)
        ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(stream_array), num_ind, key, elem) {
                php_socket_t this_fd;
 
+               ZVAL_DEREF(elem);
                php_stream_from_zval_no_verify(stream, elem);
                if (stream == NULL) {
                        continue;
@@ -698,6 +700,7 @@ static int stream_array_emulate_read_fd_set(zval *stream_array)
        zend_hash_init(Z_ARRVAL(new_array), zend_hash_num_elements(Z_ARRVAL_P(stream_array)), NULL, ZVAL_PTR_DTOR, 0);
 
        ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(stream_array), elem) {
+               ZVAL_DEREF(elem);
                php_stream_from_zval_no_verify(stream, elem);
                if (stream == NULL) {
                        continue;
diff --git a/ext/standard/tests/streams/bug72075.phpt b/ext/standard/tests/streams/bug72075.phpt
new file mode 100644 (file)
index 0000000..93dce60
--- /dev/null
@@ -0,0 +1,15 @@
+--TEST--
+Bug #72075 (Referencing socket resources breaks stream_select)
+--FILE--
+<?php
+$r = [stream_socket_server("tcp://127.0.0.1:0", $errno, $errStr)];
+$w = NULL;
+$e = NULL;
+
+// Without this line, all is well:
+$dummy =& $r[0];
+
+print stream_select($r, $w, $e, 0.5);
+
+--EXPECT--
+0