[PHP-CVS] com php-src: better fix for bug #64770: ext/standard/streamsfuncs.c ext/standard/tests/streams/bug64770.phpt

2013-05-04 Thread Anatol Belski
Commit:ec4388158d44be1f864207e633c9af562383aa75
Author:Anatol Belski  Sat, 4 May 2013 12:19:52 +0200
Parents:   f1e5127e7abe6039ccbfa9fa05b4f59bbae1097a
Branches:  PHP-5.4 PHP-5.5 master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=ec4388158d44be1f864207e633c9af562383aa75

Log:
better fix for bug #64770

Bugs:
https://bugs.php.net/64770

Changed paths:
  M  ext/standard/streamsfuncs.c
  M  ext/standard/tests/streams/bug64770.phpt


Diff:
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index d7fc68a..209cb7f 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -601,7 +601,6 @@ static int stream_array_to_fd_set(zval *stream_array, 
fd_set *fds, php_socket_t
 {
zval **elem;
php_stream *stream;
-   php_socket_t this_fd = 0;
int cnt = 0;
 
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
@@ -611,6 +610,11 @@ static int stream_array_to_fd_set(zval *stream_array, 
fd_set *fds, php_socket_t
 zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) 
&elem) == SUCCESS;
 zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
 
+   /* Temporary int fd is needed for the STREAM data type on 
windows, passing this_fd directly to php_stream_cast()
+   would eventually bring a wrong result on x64. 
php_stream_cast() casts to int internally, and this will leave
+   the higher bits of a SOCKET variable uninitialized on 
systems with little endian. */
+   int tmp_fd;
+
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
continue;
@@ -620,7 +624,9 @@ static int stream_array_to_fd_set(zval *stream_array, 
fd_set *fds, php_socket_t
 * when casting.  It is only used here so that the buffered 
data warning
 * is not displayed.
 * */
-   if (SUCCESS == php_stream_cast(stream, 
PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && 
this_fd != -1) {
+   if (SUCCESS == php_stream_cast(stream, 
PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && 
tmp_fd != -1) {
+
+   php_socket_t this_fd = (php_socket_t)tmp_fd;
 
PHP_SAFE_FD_SET(this_fd, fds);
 
@@ -638,7 +644,6 @@ static int stream_array_from_fd_set(zval *stream_array, 
fd_set *fds TSRMLS_DC)
zval **elem, **dest_elem;
php_stream *stream;
HashTable *new_hash;
-   php_socket_t this_fd = 0;
int ret = 0;
 
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
@@ -655,6 +660,11 @@ static int stream_array_from_fd_set(zval *stream_array, 
fd_set *fds TSRMLS_DC)
char *key;
uint key_len;
ulong num_ind;
+   /* Temporary int fd is needed for the STREAM data type on 
windows, passing this_fd directly to php_stream_cast()
+   would eventually bring a wrong result on x64. 
php_stream_cast() casts to int internally, and this will leave
+   the higher bits of a SOCKET variable uninitialized on 
systems with little endian. */
+   int tmp_fd;
+
 
type = zend_hash_get_current_key_ex(Z_ARRVAL_P(stream_array),
&key, &key_len, &num_ind, 0, NULL);
@@ -672,7 +682,10 @@ static int stream_array_from_fd_set(zval *stream_array, 
fd_set *fds TSRMLS_DC)
 * when casting.  It is only used here so that the buffered 
data warning
 * is not displayed.
 */
-   if (SUCCESS == php_stream_cast(stream, 
PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && 
this_fd != -1) {
+   if (SUCCESS == php_stream_cast(stream, 
PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && 
tmp_fd != -1) {
+
+   php_socket_t this_fd = (php_socket_t)tmp_fd;
+
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
if (type == HASH_KEY_IS_LONG) {
zend_hash_index_update(new_hash, 
num_ind, (void *)elem, sizeof(zval *), (void **)&dest_elem);
diff --git a/ext/standard/tests/streams/bug64770.phpt 
b/ext/standard/tests/streams/bug64770.phpt
index ae738d8..785c423 100644
--- a/ext/standard/tests/streams/bug64770.phpt
+++ b/ext/standard/tests/streams/bug64770.phpt
@@ -11,7 +11,8 @@ $descs = array(
 
 $other_opts = array('suppress_errors' => false, 'binary_pipes' => true);
 
-$p = proc_open('dir', $descs, $pipes, '.', NULL, $other_opts);
+$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls';
+$p = proc_open($cmd, $descs, $pipes, '.', NULL, $other_opts);
 
 if (is_resource($p)) {
$data = '';


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] com php-src: better fix for bug #64770: ext/standard/streamsfuncs.c ext/standard/tests/streams/bug64770.phpt

2013-05-04 Thread Anatol Belski
Commit:5c701d19aca937e28fca32934719836991b40cf0
Author:Anatol Belski  Sat, 4 May 2013 12:16:38 +0200
Parents:   f1269d80c575e535370c813e8da154e0339203d0
Branches:  PHP-5.3 PHP-5.4 PHP-5.5 master

Link:   
http://git.php.net/?p=php-src.git;a=commitdiff;h=5c701d19aca937e28fca32934719836991b40cf0

Log:
better fix for bug #64770

Bugs:
https://bugs.php.net/64770

Changed paths:
  M  ext/standard/streamsfuncs.c
  M  ext/standard/tests/streams/bug64770.phpt


Diff:
diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c
index 465d72d..20e74fe 100644
--- a/ext/standard/streamsfuncs.c
+++ b/ext/standard/streamsfuncs.c
@@ -611,7 +611,6 @@ static int stream_array_to_fd_set(zval *stream_array, 
fd_set *fds, php_socket_t
 {
zval **elem;
php_stream *stream;
-   php_socket_t this_fd = 0;
int cnt = 0;
 
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
@@ -621,6 +620,11 @@ static int stream_array_to_fd_set(zval *stream_array, 
fd_set *fds, php_socket_t
 zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) 
&elem) == SUCCESS;
 zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
 
+   /* Temporary int fd is needed for the STREAM data type on 
windows, passing this_fd directly to php_stream_cast()
+  would eventually bring a wrong result on x64. 
php_stream_cast() casts to int internally, and this will leave
+  the higher bits of a SOCKET variable uninitialized on 
systems with little endian. */
+   int tmp_fd;
+
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
continue;
@@ -630,7 +634,9 @@ static int stream_array_to_fd_set(zval *stream_array, 
fd_set *fds, php_socket_t
 * when casting.  It is only used here so that the buffered 
data warning
 * is not displayed.
 * */
-   if (SUCCESS == php_stream_cast(stream, 
PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && 
this_fd != -1) {
+   if (SUCCESS == php_stream_cast(stream, 
PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && 
tmp_fd != -1) {
+
+   php_socket_t this_fd = (php_socket_t)tmp_fd;
 
PHP_SAFE_FD_SET(this_fd, fds);
 
@@ -648,7 +654,6 @@ static int stream_array_from_fd_set(zval *stream_array, 
fd_set *fds TSRMLS_DC)
zval **elem, **dest_elem;
php_stream *stream;
HashTable *new_hash;
-   php_socket_t this_fd = 0;
int ret = 0;
 
if (Z_TYPE_P(stream_array) != IS_ARRAY) {
@@ -661,6 +666,11 @@ static int stream_array_from_fd_set(zval *stream_array, 
fd_set *fds TSRMLS_DC)
 zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) 
&elem) == SUCCESS;
 zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
 
+   /* Temporary int fd is needed for the STREAM data type on 
windows, passing this_fd directly to php_stream_cast()
+  would eventually bring a wrong result on x64. 
php_stream_cast() casts to int internally, and this will leave
+  the higher bits of a SOCKET variable uninitialized on 
systems with little endian. */
+   int tmp_fd;
+
php_stream_from_zval_no_verify(stream, elem);
if (stream == NULL) {
continue;
@@ -670,7 +680,10 @@ static int stream_array_from_fd_set(zval *stream_array, 
fd_set *fds TSRMLS_DC)
 * when casting.  It is only used here so that the buffered 
data warning
 * is not displayed.
 */
-   if (SUCCESS == php_stream_cast(stream, 
PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1) && 
this_fd != -1) {
+   if (SUCCESS == php_stream_cast(stream, 
PHP_STREAM_AS_FD_FOR_SELECT | PHP_STREAM_CAST_INTERNAL, (void*)&tmp_fd, 1) && 
tmp_fd != -1) {
+
+   php_socket_t this_fd = (php_socket_t)tmp_fd;
+
if (PHP_SAFE_FD_ISSET(this_fd, fds)) {
zend_hash_next_index_insert(new_hash, (void 
*)elem, sizeof(zval *), (void **)&dest_elem);
if (dest_elem) {
diff --git a/ext/standard/tests/streams/bug64770.phpt 
b/ext/standard/tests/streams/bug64770.phpt
index ae738d8..785c423 100644
--- a/ext/standard/tests/streams/bug64770.phpt
+++ b/ext/standard/tests/streams/bug64770.phpt
@@ -11,7 +11,8 @@ $descs = array(
 
 $other_opts = array('suppress_errors' => false, 'binary_pipes' => true);
 
-$p = proc_open('dir', $descs, $pipes, '.', NULL, $other_opts);
+$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls';
+$p = proc_open($cmd, $descs, $pipes, '.', NULL, $other_opts);
 
 if (is_resource($p)) {
$data = '';


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://ww