php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26697 calling class_exists on a nonexistent class in __autoload results in segfault
Submitted: 2003-12-22 16:03 UTC Modified: 2003-12-23 05:41 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: arjen at glas dot its dot tudelft dot nl Assigned: helly (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0b3 OS: *
Private report: No CVE-ID: None
 [2003-12-22 16:03 UTC] arjen at glas dot its dot tudelft dot nl
Description:
------------
When calling class_exists on a nonexistent classname in __autoload, you'll get a segfault.

This is in beta1, beta2 and beta3 (and now I had the time to create a testcase and do a report). Which ran under apache2 (2.0.48) on gentoo linux.

And then I saw this report:
http://bugs.php.net/bug.php?id=26630&edit=2
So I downloaded the php5-200312222030 snapshot and there it also segfaults...



Reproduce code:
---------------
<?
function __autoload($classname)
{
    if(!class_exists('test'))
    {
        echo "This won't be reached due to a segfault";
    }
}

$test = new test();

?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-22 18:50 UTC] davidc at blesys dot com
What happens, I think, is that __autoload starts recursing endlessly. Do this:

$autotracker=false;
  function __autoload ($n) {
global $autotracker; $n=strtolower($n);
 if ($autotracker==$n)die("Attempting to autoload $n again"); 
$autotracker=$n;
....//rest of function __autoload


}//end __autoload
Probably a bug, but rather easy to fix by the client programmer. I think the bug I found today w/ thrown exceptions is much more dangerous (http://bugs.php.net/bug.php?id=26698) because you can't really fix it for all cases.
 [2003-12-23 05:41 UTC] helly@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC