Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

--TEST-- Bug #60602 proc_open() modifies environment if it contains arrays --FILE-- <?php ..

Decoded Output download

--TEST--
Bug #60602 proc_open() modifies environment if it contains arrays
--FILE--
<?php

$descs = array(
    0 => array('pipe', 'r'), // stdin
    1 => array('pipe', 'w'), // stdout
    2 => array('pipe', 'w'), // strerr
);

$environment = array('test' => array(1, 2, 3));

$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls';
$p = proc_open($cmd, $descs, $pipes, '.', $environment);

if (is_resource($p)) {
    $data = '';

    while (1) {
        $w = $e = NULL;
        $n = stream_select($pipes, $w, $e, 300);

        if ($n === false) {
            echo "no streams 
";
            break;
        } else if ($n === 0) {
            echo "process timed out
";
            proc_terminate($p, 9);
            break;
        } else if ($n > 0) {
            $line = fread($pipes[1], 8192);
            if (strlen($line) == 0) {
                /* EOF */
                break;
            }
            $data .= $line;
        }
    }
    var_dump(strlen($data));

    $ret = proc_close($p);
    var_dump($ret);
    var_dump(is_array($environment['test']));
} else {
    echo "no process
";
}
?>
--EXPECTF--
Warning: Array to string conversion in %s on line %d
int(%d)
int(0)
bool(true)

Did this file decode correctly?

Original Code

--TEST--
Bug #60602 proc_open() modifies environment if it contains arrays
--FILE--
<?php

$descs = array(
    0 => array('pipe', 'r'), // stdin
    1 => array('pipe', 'w'), // stdout
    2 => array('pipe', 'w'), // strerr
);

$environment = array('test' => array(1, 2, 3));

$cmd = (substr(PHP_OS, 0, 3) == 'WIN') ? 'dir' : 'ls';
$p = proc_open($cmd, $descs, $pipes, '.', $environment);

if (is_resource($p)) {
    $data = '';

    while (1) {
        $w = $e = NULL;
        $n = stream_select($pipes, $w, $e, 300);

        if ($n === false) {
            echo "no streams \n";
            break;
        } else if ($n === 0) {
            echo "process timed out\n";
            proc_terminate($p, 9);
            break;
        } else if ($n > 0) {
            $line = fread($pipes[1], 8192);
            if (strlen($line) == 0) {
                /* EOF */
                break;
            }
            $data .= $line;
        }
    }
    var_dump(strlen($data));

    $ret = proc_close($p);
    var_dump($ret);
    var_dump(is_array($environment['test']));
} else {
    echo "no process\n";
}
?>
--EXPECTF--
Warning: Array to string conversion in %s on line %d
int(%d)
int(0)
bool(true)

Function Calls

None

Variables

$descs [{'key': 0, 'value': [{'key': 0, 'value': 'pipe'}, {'key': 1, 'value': 'r'}]}, {'key': 1, 'value': [{'key': 0, 'value': 'pipe'}, {'key': 1, 'value': 'w'}]}, {'key': 2, 'value': [{'key': 0, 'value': 'pipe'}, {'key': 1, 'value': 'w'}]}]
$environment [{'key': 'test', 'value': [{'key': 0, 'value': 1}, {'key': 1, 'value': 2}, {'key': 2, 'value': 3}]}]

Stats

MD5 bcac53a90c4e662d772816bf43c9fb1f
Eval Count 0
Decode Time 117 ms