Hi,
Thanks for the follow-up!
I couldn't test your fix in the same conditions as when I had the segfault, because there was a production application on that same server that started segfaulting too. Thing is, that production app doesn't use the Phalcon Escaper. It started segfaulting on a controller load.
So I had to revert the PHP version to PHP 5.3.3-7+squeeze15 with Suhosin-Patch (the standard PHP version for Debian Squeeze 6.0.6.
So, I've set up a small Debian 6.0.7 VM with the following:
[email protected]:~# apache2ctl -V
Server version: Apache/2.2.16 (Debian)
Server built: Mar 3 2013 12:12:28
Server's Module Magic Number: 20051115:24
Server loaded: APR 1.4.2, APR-Util 1.3.9
Compiled using: APR 1.4.2, APR-Util 1.3.9
Architecture: 64-bit
Server MPM: Worker
threaded: yes (fixed thread count)
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/worker"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/etc/apache2"
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="mime.types"
-D SERVER_CONFIG_FILE="apache2.conf"
[email protected]:~# php5-cgi -v
PHP 5.4.15-1~dotdeb.1 (cgi-fcgi) (built: May 11 2013 19:55:28)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
I had some compiler warnings when building Phalcon 1.2.0, including the escaper code:
/home/steven/cphalcon/build/64bits/phalcon.c -fPIC -DPIC -o .libs/phalcon.o
/home/steven/cphalcon/build/64bits/phalcon.c: In function ‘phalcon_escape_html’:
/home/steven/cphalcon/build/64bits/phalcon.c:7939: warning: passing argument 3 of ‘php_escape_html_entities’ from incompatible pointer type
/usr/include/php5/ext/standard/html.h:57: note: expected ‘size_t *’ but argument is of type ‘unsigned int *’
/home/steven/cphalcon/build/64bits/phalcon.c: In function ‘phalcon_exp_call_method’:
/home/steven/cphalcon/build/64bits/phalcon.c:10887: warning: passing argument 1 of ‘phalcon_start_with_str_str’ discards qualifiers from pointer target type
/home/steven/cphalcon/build/64bits/phalcon.c:7229: note: expected ‘char *’ but argument is of type ‘const char *’
I've setup the following code using the .htaccess and index.php from the Phalcon tutorial https://github.com/phalcon/tutorial on a standard Phalcon app directory layout:
app/controllers/IndexController.php:
<?php
class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
$e = new \Phalcon\Escaper;
// exit('fraise tagada');
exit($e->escapeHtml('fraise tagada'));
}
}
This code does not segfault using Phalcon 1.2.0.
The same code segfaults using Phalcon 1.1.0 on the very same setup.
I went a bit further and tested with the same PHP version (5.4.15) but as Apache module:
It segfaults using Phalcon 1.1.0
It does not segfault using Phalcon 1.2.0
Although it seems you caught the bug, it doesn't really seemed to be related to the escaper code, although using that code reliably provokes the segfault ;)
Hope this helps you further improving a great framework!
Best,
Steven
P.S.: Stumbled upon the same compiler warnings for Phalcon 1.1.0 as well:
/home/steven/cphalcon/build/64bits/phalcon.c -fPIC -DPIC -o .libs/phalcon.o
/home/steven/cphalcon/build/64bits/phalcon.c: In function ‘phalcon_escape_html’:
/home/steven/cphalcon/build/64bits/phalcon.c:7939: warning: passing argument 3 of ‘php_escape_html_entities’ from incompatible pointer type
/usr/include/php5/ext/standard/html.h:57: note: expected ‘size_t *’ but argument is of type ‘unsigned int *’
/home/steven/cphalcon/build/64bits/phalcon.c: In function ‘phalcon_exp_call_method’:
/home/steven/cphalcon/build/64bits/phalcon.c:10887: warning: passing argument 1 of ‘phalcon_start_with_str_str’ discards qualifiers from pointer target type
/home/steven/cphalcon/build/64bits/phalcon.c:7229: note: expected ‘char *’ but argument is of type ‘const char *’