php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77179 debug_backtrace() — Callstack arg values are modified inside the callee
Submitted: 2018-11-20 00:01 UTC Modified: 2018-11-20 00:28 UTC
From: signe at cothlamadh dot net Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.2.12 OS: macOS 10.14.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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: signe at cothlamadh dot net
New email:
PHP Version: OS:

 

 [2018-11-20 00:01 UTC] signe at cothlamadh dot net
Description:
------------
If a function modifies one of its parameters internally (not via reference), the argument list returned by the backtrace functions reflects the modification not the initial value.

The callstack arguments are being modified after the call is made.  Interestingly, this doesn't seem to affect functions which are using their default parameters.

Occurs in both debug_backtrace() and debug_print_backtrace()

Test script calls a pair of recursing functions — in the first, a parameter is passed to the top-most function normally.  In the second, the parameter's default value is used.

Stack entry #10 is modified in the first case and not in the second.

Test script:
---------------
<?php
echo "''\n";
foo('');

echo "\n\n";

echo "NULL\n";
foo();

function foo($str = '') {
    if (strlen($str) >= 30) {
        debug_print_backtrace();
        return;
    }

    $str .= 'foo';
    echo "'$str'\n";

    bar($str);
}

function bar($str) {
    $str .= 'bar';
    echo "'$str'\n";;

    foo($str);
}

Expected result:
----------------
''
'foo'
'foobar'
'foobarfoo'
'foobarfoobar'
'foobarfoobarfoo'
'foobarfoobarfoobar'
'foobarfoobarfoobarfoo'
'foobarfoobarfoobarfoobar'
'foobarfoobarfoobarfoobarfoo'
'foobarfoobarfoobarfoobarfoobar'
#0  foo(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26]
#1  bar(foobarfoobarfoobarfoobarfoo) called at [/private/tmp/foo.php:19]
#2  foo(foobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26]
#3  bar(foobarfoobarfoobarfoo) called at [/private/tmp/foo.php:19]
#4  foo(foobarfoobarfoobar) called at [/private/tmp/foo.php:26]
#5  bar(foobarfoobarfoo) called at [/private/tmp/foo.php:19]
#6  foo(foobarfoobar) called at [/private/tmp/foo.php:26]
#7  bar(foobarfoo) called at [/private/tmp/foo.php:19]
#8  foo(foobar) called at [/private/tmp/foo.php:26]
#9  bar(foo) called at [/private/tmp/foo.php:19]
#10 foo() called at [/private/tmp/foo.php:3]


NULL
'foo'
'foobar'
'foobarfoo'
'foobarfoobar'
'foobarfoobarfoo'
'foobarfoobarfoobar'
'foobarfoobarfoobarfoo'
'foobarfoobarfoobarfoobar'
'foobarfoobarfoobarfoobarfoo'
'foobarfoobarfoobarfoobarfoobar'
#0  foo(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26]
#1  bar(foobarfoobarfoobarfoobarfoo) called at [/private/tmp/foo.php:19]
#2  foo(foobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26]
#3  bar(foobarfoobarfoobarfoo) called at [/private/tmp/foo.php:19]
#4  foo(foobarfoobarfoobar) called at [/private/tmp/foo.php:26]
#5  bar(foobarfoobarfoo) called at [/private/tmp/foo.php:19]
#6  foo(foobarfoobar) called at [/private/tmp/foo.php:26]
#7  bar(foobarfoo) called at [/private/tmp/foo.php:19]
#8  foo(foobar) called at [/private/tmp/foo.php:26]
#9  bar(foo) called at [/private/tmp/foo.php:38]
#10 foo() called at [/private/tmp/foo.php:8]

Actual result:
--------------
''
'foo'
'foobar'
'foobarfoo'
'foobarfoobar'
'foobarfoobarfoo'
'foobarfoobarfoobar'
'foobarfoobarfoobarfoo'
'foobarfoobarfoobarfoobar'
'foobarfoobarfoobarfoobarfoo'
'foobarfoobarfoobarfoobarfoobar'
#0  foo(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26]
#1  bar(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:19]
#2  foo(foobarfoobarfoobarfoobarfoo) called at [/private/tmp/foo.php:26]
#3  bar(foobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:19]
#4  foo(foobarfoobarfoobarfoo) called at [/private/tmp/foo.php:26]
#5  bar(foobarfoobarfoobar) called at [/private/tmp/foo.php:19]
#6  foo(foobarfoobarfoo) called at [/private/tmp/foo.php:26]
#7  bar(foobarfoobar) called at [/private/tmp/foo.php:19]
#8  foo(foobarfoo) called at [/private/tmp/foo.php:26]
#9  bar(foobar) called at [/private/tmp/foo.php:19]
#10 foo(foo) called at [/private/tmp/foo.php:3]


NULL
'foo'
'foobar'
'foobarfoo'
'foobarfoobar'
'foobarfoobarfoo'
'foobarfoobarfoobar'
'foobarfoobarfoobarfoo'
'foobarfoobarfoobarfoobar'
'foobarfoobarfoobarfoobarfoo'
'foobarfoobarfoobarfoobarfoobar'
#0  foo(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:26]
#1  bar(foobarfoobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:19]
#2  foo(foobarfoobarfoobarfoobarfoo) called at [/private/tmp/foo.php:26]
#3  bar(foobarfoobarfoobarfoobar) called at [/private/tmp/foo.php:19]
#4  foo(foobarfoobarfoobarfoo) called at [/private/tmp/foo.php:26]
#5  bar(foobarfoobarfoobar) called at [/private/tmp/foo.php:19]
#6  foo(foobarfoobarfoo) called at [/private/tmp/foo.php:26]
#7  bar(foobarfoobar) called at [/private/tmp/foo.php:19]
#8  foo(foobarfoo) called at [/private/tmp/foo.php:26]
#9  bar(foobar) called at [/private/tmp/foo.php:38]
#10 foo() called at [/private/tmp/foo.php:8]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-20 00:28 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2018-11-20 00:28 UTC] requinix@php.net
> If a function modifies one of its parameters internally (not via reference),
> the argument list returned by the backtrace functions reflects the modification
> not the initial value.
Correct. This is for performance reasons, as stated in bug #72002.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC