|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75864 "stream_isatty" returns wrong value on s390x
Submitted: 2018-01-23 18:38 UTC Modified: 2018-01-27 16:27 UTC
From: samding at ca dot ibm dot com Assigned: ab (profile)
Status: Closed Package: Streams related
PHP Version: 7.2.1 OS: RHEL 7.2
Private report: No CVE-ID: None
 [2018-01-23 18:38 UTC] samding at ca dot ibm dot com
Test cases 
   Test stream_isatty with redirected STDERR [tests/output/stream_isatty_err.phpt]
   Test stream_isatty with redirected STDIN/STDERR [tests/output/stream_isatty_in-err.phpt]
   Test stream_isatty with redirected STDIN/STDOUT [tests/output/stream_isatty_in-out.phpt]
   Test stream_isatty with redirected STDOUT [tests/output/stream_isatty_out.phpt]
   Test stream_isatty with redirected STDOUT/STDERR [tests/output/stream_isatty_out-err.phpt]
Failed on s390x. 

Test script:
Here is sample php code:


       $closeMe = fopen(__FILE__, 'rb');
       echo "closeme=$closeMe, stream_isatty=$tmp+\n";
       echo "closeMe:"; var_dump(stream_isatty($closeMe));

gdb sapi/cli/php 
(gdb) b zif_stream_isatty
(gdb) r case/sample.php
1651            RETVAL_BOOL(isatty(fileno));
(gdb) p fileno
$1 = 34359718632 
(gdb) x /8b &fileno
0x3ffffffb360:  0       0       0       7       -1      -1      -78     -24

Seems the last 4 bytes of "fileno" wrong on s390x (Big_Endian)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-23 21:27 UTC] samding at ca dot ibm dot com
The root reason happens at /home/work/php/php_master/main/streams/plain_wrapper.c:578

578                                     *(php_socket_t *)ret = fd;
Note "php_socket_t" is int type (4 bytes) and "ret" (fileno) is long (8 bytes).
This point operation is sensitive on Big/Little Endian platform, it is ok on LE, but causes the issue on BE.

The solution is change "fileno" to int type.
 [2018-01-27 16:27 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: ab
 [2018-01-27 16:27 UTC]
Fixed per a8c6b36d62b1a58be68a1e50ee4113351f1845e4.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 22 13:01:24 2023 UTC