php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41828 Failing to call RecursiveIteratorIterator::__construct() causes a sefault
Submitted: 2007-06-27 18:40 UTC Modified: 2008-03-12 13:40 UTC
From: eric dot gach at gmail dot com Assigned: colder
Status: Closed Package: SPL related
PHP Version: 5.2.3 OS: Any
Private report: No CVE-ID:
 [2007-06-27 18:40 UTC] eric dot gach at gmail dot com
Description:
------------
When creating a class that extends RecursiveIteratorIterator, it causes a sefault if the __construct() method of the new class does not call RecursiveIteratorIterator::__construct(). 

I'm reporting this bug because I would expect to see PHP throw a fatal error about RecursiveIteratorIterator::__construct() not being initalized instead of segfaulting. This happens from the CLI and through Apache using libphp5.so

The backtrace I have included is from 5.2.2, but I have verified that it causes a segfault on 5.2.3 as well.

~ Eric

Reproduce code:
---------------
<?php
class foo extends RecursiveIteratorIterator {
    private $_bar;

    public function __construct($str) {
        $this->_bar = $str;
    }

    public function bar() {
        return $this->_bar;
    }
}

$foo = new foo("This is bar");
echo $foo->bar();
?>

Expected result:
----------------
Output:
This is bar

Actual result:
--------------
Segmentation Fault

Backtrace:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 47957714823424 (LWP 9682)]
0x00000000005e7cbe in spl_recursive_it_get_method (object_ptr=0x7fffa7c67cb8,
   method=0xe09798 "bar", method_len=3, tsrm_ls=0xbc0030)
   at /home/mirashii/php-sources/php-5.2.2/ext/spl/spl_iterators.c:696
696             zval                    *zobj =
object->iterators[level].zobject;

(gdb) bt
#0  0x00000000005e7cbe in spl_recursive_it_get_method (
   object_ptr=0x7fffa7c67cb8, method=0xe09798 "bar", method_len=3,
   tsrm_ls=0xbc0030)
   at /home/mirashii/php-sources/php-5.2.2/ext/spl/spl_iterators.c:696
#1  0x000000000080feab in ZEND_INIT_METHOD_CALL_SPEC_CV_CONST_HANDLER (
   execute_data=0x7fffa7c67c70, tsrm_ls=0xbc0030)
   at /home/mirashii/php-sources/php-5.2.2/Zend/zend_vm_execute.h:21218
#2  0x00000000007c07e1 in execute (op_array=0xe03090, tsrm_ls=0xbc0030)
   at /home/mirashii/php-sources/php-5.2.2/Zend/zend_vm_execute.h:92
#3  0x000000000078361c in zend_eval_string (
   str=0x7fffa7c68871 "class foo extends RecursiveIteratorIterator {
private $_bar; public function __construct($str) { $this->_bar = $str;
} public function bar() { return $this->_bar; } } $foo = new
foo(\"This is bar\"); $f"...,
   retval_ptr=0x0, string_name=0x91bee4 "Command line code", tsrm_ls=0xbc0030)
   at /home/mirashii/php-sources/php-5.2.2/Zend/zend_execute_API.c:1148
#4  0x0000000000783840 in zend_eval_string_ex (
   str=0x7fffa7c68871 "class foo extends RecursiveIteratorIterator {
private $_bar; public function __construct($str) { $this->_bar = $str;
} public function bar() { return $this->_bar; } } $foo = new
foo(\"This is bar\"); $f"...,
   retval_ptr=0x0, string_name=0x91bee4 "Command line code",
   handle_exceptions=1, tsrm_ls=0xbc0030)
   at /home/mirashii/php-sources/php-5.2.2/Zend/zend_execute_API.c:1182
#5  0x000000000082510e in main (argc=3, argv=0x7fffa7c68258)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-27 21:03 UTC] tony2001@php.net
I guess, there should be a check like this: http://dev.daylessday.org/diff/bug41828.diff
Marcus, please take a look at it.
 [2008-03-12 13:40 UTC] colder@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.

Thanks for the patch Tony.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 24 02:02:10 2014 UTC