Bug #78395 [NEW]: Exception::getTrace references can modify original reference vars from stack
| From: | src at enobrev dot com | Date: | Fri, 09 Aug 2019 19:46:57 +0000 |
| Subject: | Bug #78395 [NEW]: Exception::getTrace references can modify original reference vars from stack | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222165@lists.php.net to get a copy of this message | ||
From: src at enobrev dot com
Operating system: Ubuntu 19.04
PHP version: 7.2.21
Package: *General Issues
Bug Type: Bug
Bug description:Exception::getTrace references can modify original reference vars from stack
Description:
------------
If using references while looping through the results of
Exception::getTrace, changing the args of a function with a referenced
parameter in the stack will change the original referenced parameter.
Maybe this is considered correct and just needs to be documented, but I
had assumed the result in Exception::getTrace would be a copy of the
arguments, not references to the actual arguments.
(this was originally discovered by https://github.com/victusfate)
Test script:
---------------
$a = ['array' => 'of stuff', 'toodles' => 14 ];
function boom(array &$b) {
throw new Exception('kablooey');
}
try {
boom($a);
} catch(Exception $e) {
echo var_dump($a);
$aStack = $e->getTrace();
foreach($aStack as &$aItem) {
if(isset($aItem['args'])) {
foreach($aItem['args'] as &$aArg) {
$aArg = 'destroyed';
}
}
}
echo var_dump($a);
}
Expected result:
----------------
array(2) {
["array"]=>
string(8) "of stuff"
["toodles"]=>
int(14)
}
array(2) {
["array"]=>
string(8) "of stuff"
["toodles"]=>
int(14)
}
Actual result:
--------------
array(2) {
["array"]=>
string(8) "of stuff"
["toodles"]=>
int(14)
}
string(9) "destroyed"
--
Edit bug report at https://bugs.php.net/bug.php?id=78395&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78395&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78395&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78395&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78395&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78395&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78395&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78395&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78395&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78395&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78395&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78395&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78395&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78395&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78395&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78395&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78395&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78395&r=mysqlcfg