Bug #77179 [NEW]: debug_backtrace() â Callstack arg values are modified inside the callee
| From: | signe at cothlamadh dot net | Date: | Tue, 20 Nov 2018 00:01:45 +0000 |
| Subject: | Bug #77179 [NEW]: debug_backtrace() â Callstack arg values are modified inside the callee | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-218053@lists.php.net to get a copy of this message | ||
From: signe at cothlamadh dot net
Operating system: macOS 10.14.2
PHP version: 7.2.12
Package: Scripting Engine problem
Bug Type: Bug
Bug description:debug_backtrace() â Callstack arg values are modified inside the callee
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]
--
Edit bug report at https://bugs.php.net/bug.php?id=77179&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77179&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77179&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77179&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77179&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77179&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77179&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77179&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77179&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77179&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77179&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77179&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77179&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77179&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77179&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77179&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77179&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77179&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77179&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77179&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77179&r=mysqlcfg