Bug #68709 [NEW]: Segfault when parent::offsetGet() is called

From: Date: Thu, 01 Jan 2015 12:38:53 +0000
Subject: Bug #68709 [NEW]: Segfault when parent::offsetGet() is called
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189576@lists.php.net to get a copy of this message
From:             zecho23 at gmail dot com
Operating system: Debian 8
PHP version:      5.6.4
Package:          Reproducible crash
Bug Type:         Bug
Bug description:Segfault when parent::offsetGet() is called

Description:
------------
I had some old code running for years (since PHP 5.3.x). After upgrade
it started to segfault in a overwritten offsetGet method in a class
implementing ArrayAccess. After debugging it I reached the broken code
at following function made long ago:

  public function offsetGet($key)
  {
    if (in_array($key, array_keys($this->_structure), true) &&
!isset($this[$key]))
    {
      return null;
    }

    return (parent::offsetExists($key)) ? parent::offsetGet($key) :
null;
  }

The result at dbg:

Program received signal SIGSEGV, Segmentation fault.
zend_call_method (object_pp=object_pp@entry=0x7fffff7ff078,
obj_ce=0x1d14658, fn_proxy=fn_proxy@entry=0x1d5beb0, 
    function_name=function_name@entry=0xb2598c "offsetGet",
function_name_len=function_name_len@entry=9, 
    retval_ptr_ptr=retval_ptr_ptr@entry=0x7fffff7ff088, param_count=1,
arg1=0x2059d28, arg2=0x0)
    at /build/php5-NIujy4/php5-5.6.4+dfsg/Zend/zend_interfaces.c:47
47      in /build/php5-NIujy4/php5-5.6.4+dfsg/Zend/zend_interfaces.c

I made it work after changing the last tine to:

    return (parent::offsetExists($key)) ? $this->_structure[$key] :
null;                                          

Hope that helps.


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



Thread (3 messages)

« previous php.bugs (#189576) next »