php.net |  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
Description:
------------
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:

<?php

       $closeMe = fopen(__FILE__, 'rb');
       $tmp=stream_isatty($closeMe);
       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)


Patches

Pull Requests

History

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] ab@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ab
 [2018-01-27 16:27 UTC] ab@php.net
Fixed per a8c6b36d62b1a58be68a1e50ee4113351f1845e4.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC