Bug #79108 [NEW]: Referencing argument in a function makes it a reference in the stack trace

From: Date: Mon, 13 Jan 2020 10:26:40 +0000
Subject: Bug #79108 [NEW]: Referencing argument in a function makes it a reference in the stack trace
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224874@lists.php.net to get a copy of this message
From:             tux dot jumale at gmail dot com
Operating system: 7.2.26-cli-alpine3.10
PHP version:      7.2.26
Package:          *General Issues
Bug Type:         Bug
Bug description:Referencing argument in a function makes it a reference in the stack trace

Description:
------------
Taking a reference of an argument makes it also to be a reference in the
stack trace, which allows to modify the value from any nesting level via
'args' key of debug_backtrace

Test script:
---------------
<?php

function test(string $val) {
    $a = &$val;
    hackingHere();
    print_r($val);
}

function hackingHere() {
    // we're able to modify the $val from here, even though the arg was
not a reference
    debug_backtrace()[1]['args'][0] = 'Modified';
}

test('Original');

Expected result:
----------------
Should print 'Original'

Actual result:
--------------
Prints 'Modified', because hackingHere unexpectedly gets access to the
argument.


-- 
Edit bug report at https://bugs.php.net/bug.php?id=79108&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79108&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79108&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79108&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79108&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79108&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79108&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79108&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79108&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79108&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79108&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79108&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79108&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79108&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79108&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79108&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79108&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79108&r=mysqlcfg


Thread (5 messages)

« previous php.bugs (#224874) next »