From:             emiel dot mols at gmail dot com
Operating system: Irrelevant
PHP version:      5.5Git-2013-04-03 (snap)
Package:          Reproducible crash
Bug Type:         Bug
Bug description:debug_backtrace in set_error_handler corrupts zend heap: 
segfault

Description:
------------
So I thought the other day it might be convenient to grab a stack trace in,
you 
know, the place errors are handled. Apparently, PHP thinks this is a
terrible 
idea.

The exact cause is unclear, but I've managed to create a decently small
test 
case that segfaults both on Debian PHP 5.4.4 and Darwin PHP 5.5 nightly.

In the attached test script, the call to x() should generate an error,
because 
accessing a string as associative array is forbidden.

- the segfault occurs in native _zend_mm_free_int
- only able to replicate when there's a function call on the PHP stack
- it appears debug_backtrace is only corrupting the stack -- the call to 
print_r() initiates the segfault.
- i've seen $y change every access (eg containing random other variables,
or 
just random heap garbage).
- in narrowing down the specific case, I've also often seen messages along
the 
lines of "mm stack corrupt"

Core dumps can be found at:
- Debian: http://db.tt/aA5wAx7a (16MB)
- Darwin: http://db.tt/gxZrP8Pa (400MB)

Test script:
---------------
<?php

set_error_handler(function() { debug_backtrace(); });

function x($s) { $s['a'] = 1; };
$y = '1';
x($y);
print_r($y);


Expected result:
----------------
Being able to use debug_backtrace() in error handlers.

Actual result:
--------------
A corrupt heap, resulting in a freaking segfault.

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

Reply via email to