From: dmitry dot koterov at gmail dot com
Operating system: Linux
PHP version: 5.2.8
PHP Bug Type: Reproducible crash
Bug description: Command like stream_filter_prepend(STDOUT, "strtoupper")
crashes PHP
Description:
------------
I am trying to redirect default STDOUT to some other place (e.g. to a
stream socket or just handle it via stream filter).
And I reproduce the PHP crash.
P.S.
Is it possibly at all to redirect STDOUT to some other place (e.g.
socket)? It is needed for me to create socket-listening daemon. Usual
"echo" commands should be redirected to socket. Ob_start() is not enough
for me, because somewhere in server code OB level nesting may be
accidentally broken, so I am looking for PHP's equivalent to Perl's
"open(STDOUT, '>&SOCK')".
Reproduce code:
---------------
<?php
class strtoupper_filter extends php_user_filter {
function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
stream_filter_register("strtoupper", "strtoupper_filter")
or die("Failed to register filter");
stream_filter_prepend(STDOUT, "strtoupper");
echo "abcd\n";
Expected result:
----------------
ABCD
or at least
abcd
Actual result:
--------------
abcd
Segmentation fault
--
Edit bug report at http://bugs.php.net/?id=46911&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=46911&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=46911&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=46911&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=46911&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=46911&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=46911&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=46911&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=46911&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=46911&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=46911&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=46911&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=46911&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=46911&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=46911&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46911&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=46911&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=46911&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=46911&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=46911&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=46911&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=46911&r=mysqlcfg