From: kaien at sparcs dot org
Operating system: Linux
PHP version: 5.1.6
PHP Bug Type: Scripting Engine problem
Bug description: Engine crashes with function with default parameters, with
opcode cache.
Description:
------------
Function with default parameters consisting of an array of string elements
causes a race condition leading to engine crash when used with opcode
cache.
ZEND_RECV_INIT handler duplicates the array hashtable itself, but does not
duplicate each individual elements from shm, AND only increments the
refcount of the default parameter array element.
So, zval_copy_ctor and zval_dtor modifies the zval refcount of the array
element without any mutex, which causes an engine crash.
Tested on php5 with Zend performance suite and eaccelerator, with 2way,
4way boxes.
I guess there will be same problem on php4 too.
I know this is not just bug of script engine alone,
but I guess the engine should not modify compiled opcodes while
executing.
Reproduce code:
---------------
script.php:
<?
function a($cols = array("AAA", "BBB"))
{
$cols = implode(',', $cols);
$query = "select $cols";
}
a();
?>
% ab -n 100000 -c 10 http://localhost/script.php
Expected result:
----------------
No segv.
Actual result:
--------------
Repeated segv after refcount of string zval("AAA") becomes 0.
(stacktrace points to zval_dtor/efree() called on zval("AAA") in shm,
because refcount == 0.)
--
Edit bug report at http://bugs.php.net/?id=38878&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=38878&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=38878&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=38878&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38878&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=38878&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38878&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38878&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38878&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38878&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38878&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=38878&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=38878&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38878&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38878&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38878&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38878&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38878&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38878&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38878&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38878&r=mysqlcfg