php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75873 pcntl_wexitstatus returns incorrect on Big_Endian platform (s390x)
Submitted: 2018-01-25 15:34 UTC Modified: 2018-02-23 22:59 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: samding at ca dot ibm dot com Assigned: cmb (profile)
Status: Closed Package: PCNTL related
PHP Version: 7.2.1 OS: RHEL7.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: samding at ca dot ibm dot com
New email:
PHP Version: OS:

 

 [2018-01-25 15:34 UTC] samding at ca dot ibm dot com
Description:
------------
Test case "ext/pcntl/tests/001.phpt" show it result on big_endian platform:

"
Staring wait.h tests....

Testing pcntl_wifexited and wexitstatus....
Exited With: 0

Testing pcntl_wifsignaled....

Testing pcntl_wifstopped and pcntl_wstopsig....
"

Test script:
---------------
 sapi/cli/php ext/pcntl/tests/001.php

Expected result:
----------------
"pcntl_wifexited" should return "255"

Actual result:
--------------
"pcntl_wifexited" should return "0"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-25 15:51 UTC] samding at ca dot ibm dot com
See the code of "pcntl_wexitstatus" of ext/pcntl/pcntl.c

    841 PHP_FUNCTION(pcntl_wexitstatus)
    842 {
    843 #ifdef WEXITSTATUS
    844         zend_long status_word;
    845
    846         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &status_word) == FAILURE) {
    847                return;
    848         }
    849         RETURN_LONG(WEXITSTATUS(status_word));
    850 #else
    851         RETURN_FALSE;
    852 #endif

Here status_word is long, but WEXITSTATUS needs the input as int.(https://www.gnu.org/software/libc/manual/html_node/Process-Completion-Status.html)
This is no problem on Little_Endian, but causes the problem on Big_Endian platform (s390x).

Have to cast it to int before running macro WEXITSTATUS:

    849         RETURN_LONG(WEXITSTATUS((int)status_word));

Similarly following function need to change:

pcntl_wifexited
pcntl_wifstopped
pcntl_wifsignaled
pcntl_wifcontinued
pcntl_wexitstatus
pcntl_wtermsig
pcntl_wstopsig
 [2018-02-23 22:59 UTC] cmb@php.net
Automatic comment on behalf of samding@ca.ibm.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=78c1ef2adbd3f9383659326cc85e7f45fef639ae
Log: Fix #75873: pcntl_wexitstatus returns incorrect on Big_Endian platform (s390x)
 [2018-02-23 22:59 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2018-02-23 22:59 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Feb 03 01:01:31 2025 UTC