php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43179 Segfault on combo of recursive array, class members and variable variables
Submitted: 2007-11-02 15:55 UTC Modified: 2007-11-02 17:07 UTC
From: php at lorddeath dot net Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.4 OS: Windows / Linux
Private report: No CVE-ID: None
 [2007-11-02 15:55 UTC] php at lorddeath dot net
Description:
------------
When the code I've supplied is executed, PHP crashes, leaving a segfault message in Apache's log.

The code looks a little perverse, though a variation on it had a real use in my situation, but regardless, PHP shouldn't segfault, no matter how perverse the code is :)

Reproduce code:
---------------
class MC {
	public $Vars = array();
	public function Execute() {
		if (!defined('DONE')) {
			define('DONE', true);
			foreach ($this->Vars as $k => $v) { $$k = $v; }
			$MyArr['Var'] = $MyArr;
			$MC = new MC();
			$MC->Vars = $MyArr;
			$MC->Execute();
		}
	}
}
$MyArr = array();
$MyArr['Var'] = $MyArr;
$MC = new MC();
$MC->Vars = $MyArr;
$MC->Execute();
echo "Hello world.";

Expected result:
----------------
"Hello world." should be printed.

Actual result:
--------------
Nothing is printed, and a segfault line is added to /var/log/apache2/error.log:
[Fri Nov 02 15:50:11 2007] [notice] child pid 23282 exit signal Segmentation fault (11)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-02 15:59 UTC] php at lorddeath dot net
Sorry; got the code wrong.  This, however, segfaults as "expected":
<?
class MC {
	public $Vars = array();
	public function Execute() {
		foreach ($this->Vars as $k => $v) { $$k = $v; }
		$MyArr['Var'] = $MyArr;
		$MC = new MC();
		$MC->Vars = $MyArr;
		$MC->Execute();
	}
}
$MyArr = array();
$MyArr['Var'] = $MyArr;
$MC = new MC();
$MC->Vars = $MyArr;
$MC->Execute();
echo "Hello world.";
?>
 [2007-11-02 17:07 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That\'s an infinite recursion which will use all stack space.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 02:01:29 2024 UTC