php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14374 Reproductible crash (simple script) related to default variables/arrays
Submitted: 2001-12-07 06:09 UTC Modified: 2001-12-07 06:28 UTC
From: xroche at free dot fr Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.6 OS: Linux 2.2.20
Private report: No CVE-ID: None
 [2001-12-07 06:09 UTC] xroche at free dot fr
This following simple script will crash both PHP 4.06 (module and cgi) and previous 4.05 but NOT 4.03pl1 (?!), and might be related to the following bug ID's:
Bug id #12776
Bug id #14281

It seems that there's a problem between array variables, default values and empty arrays accessed through index (a null variable used as array using an index)
If you change the code and delete the first foo variable (in function and in the call), this won't crash (!)
I am still trying to simplify this code to find an immediate and obvious cause for the core dump, but IMHO this script is yet simple enough to detect a problem.


<pre>
<?php

// will work without first dummy parameter
Function FooBar($foo,$depth=10,$bar=array()) {

	if ($depth<0)
		return "";

	// echo ..
	echo "in FooBar (".$depth.")\n";

	// This part will cause damages soon
	return 		FooBar($foo,$depth-1,$bar)
		.	FooBar2("",$bar)
		.	$foo["foo_bar"][13345879];
}

// will work without first dummy parameter
Function FooBar2($foo,$bar=array()) {

	// This part shall seg fault ..
	if (!$bar["foo_bar"]) {
		$bar["foo_bar"]=$bar["foo_bar"]+1;
	}

	// echo ..
	echo "in FooBar2 (".$foo.")\n";

	// This part will cause memory damages..
	$if_I_do_that_this_will_crash=serialize($bar);

	return "";
}

FooBar("");

?>
</pre>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-07 06:15 UTC] derick@php.net
I can not reproduce this with php 4.1.0RC5 or php 4.2.0dev, so considered fixed.
(You can try yourself with www.php.net/~zeev/php-4.1.0RC5.tar.gz)
PHP 4.1.0 will be released in a few days now.

Derick
 [2001-12-07 06:28 UTC] xroche at free dot fr
Seems to be fixed in CVS, sorry!

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 08:01:27 2025 UTC