php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28306 PHP5-rc2 coredumps with Smarty-2.6.2, error handler and exceptions
Submitted: 2004-05-06 19:55 UTC Modified: 2005-01-18 22:50 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:3 (100.0%)
From: cunha17 at gmail dot com Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 5CVS-2004-05-06 (dev) OS: Redhat Linux 9/Fedora Core 1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cunha17 at gmail dot com
New email:
PHP Version: OS:

 

 [2004-05-06 19:55 UTC] cunha17 at gmail dot com
Description:
------------
First of all:
1. Using PHP-RC2 or PHP-CVS (2004-05-06)
2. Using Smarty-2.6.2 with customized tag(function)
3. Mapping PHP errors to exceptions(user error handler)

If there is an error inside the customized Smarty function, the error handler routine raises an exception that doesn't reach any try/catch block outside the Smarty class.

In fact, the exception doesn't propagate outside the fetch function in file Smarty.class.php.

The exception is raised inside an "include" instruction and it's possible to catch it inside the fetch function, but impossible anywhere else.

The fetch function is called from Smarty.class.php:1115 and the "include" instruction is placed at Smarty.class.php:1266.

Cristiano Duarte

Reproduce code:
---------------
<?php
include('Smarty-2.6.2/libs/Smarty.class.php');
function smarty_test($params, $smarty)
{
        //Now we raise a notice about name not being defined
        //This should get mapped to an Exception
        return "{$params[name]}";
}
                                                                                
function my_error($nr, $text, $file, $line, $vars)
{
        $e = new Exception($text);
        throw $e;
}
error_reporting(E_ALL);
set_error_handler('my_error');
                                                                                
$s = new Smarty();
$s->register_function('test', 'smarty_test');
$s->display('exception_bug.tpl');
?>

Here is the template(exception_bug.tpl):
<html>
<head>
<title>Exception BUG</title>
</head>
<body>
{test name="ExceptionBugTest"}
</body>
</html>

Expected result:
----------------
Uncaught Exception 

Actual result:
--------------
Segmentation Fault (core dumped)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-06 19:58 UTC] cunha17 at uol dot com dot br
The debug_backtrace() just before the segmentation fault:

Array
(
    [0] => Array
        (
            [file] => /home/ten_cunha/bug/templates_c/%%595^%%595330115^exception_bug.tpl.php
            [line] => 10
            [function] => smarty_test
            [args] => Array
                (
                    [0] => Array
                        (
                            [name] => ExceptionBugTest
                        )
 
                    [1] => Smarty Object
                        (
                            [template_dir] => templates
                            [compile_dir] => templates_c
                            [config_dir] => configs
                            [plugins_dir] => Array
                                (
                                    [0] => plugins
                                )
 
                            [debugging] =>
                            [error_reporting] =>
                            [debug_tpl] =>
                            [debugging_ctrl] => NONE
                            [compile_check] => 1
                            [force_compile] =>
                            [caching] => 0
                            [cache_dir] => cache
                            [cache_lifetime] => 3600
                            [cache_modified_check] =>
                            [php_handling] => 0
                            [security] =>
                            [secure_dir] => Array
                                (
                                )
 
                            [security_settings] => Array
                                (
                                    [PHP_HANDLING] =>
                                    [IF_FUNCS] => Array
                                        (
                                            [0] => array
                                            [1] => list
                                            [2] => isset
                                            [3] => empty
                                            [4] => count
                                            [5] => sizeof
                                            [6] => in_array
                                            [7] => is_array
                                            [8] => true
                                            [9] => false
                                        )
 
                                    [INCLUDE_ANY] =>
                                    [PHP_TAGS] =>
                                    [MODIFIER_FUNCS] => Array
                                        (
                                            [0] => count
                                        )
 
                                    [ALLOW_CONSTANTS] =>
                                )
 
                            [trusted_dir] => Array
                                (
                                )
 
                            [left_delimiter] => {
                            [right_delimiter] => }
                            [request_vars_order] => EGPCS
                            [request_use_auto_globals] => 1
                            [compile_id] =>
                            [use_sub_dirs] =>
                            [default_modifiers] => Array
                                (
                                )
 
                            [default_resource_type] => file
                            [cache_handler_func] =>
                            [autoload_filters] => Array
                                (
                                )
 
                            [config_overwrite] => 1
                            [config_booleanize] => 1
                            [config_read_hidden] =>
                            [config_fix_newlines] => 1
                            [default_template_handler_func] =>
                            [compiler_file] => Smarty_Compiler.class.php
                            [compiler_class] => Smarty_Compiler
                            [config_class] => Config_File
                            [_error_msg] =>
                            [_tpl_vars] => Array
                                (
                                    [SCRIPT_NAME] => exception_bug.php
                                )
 
                            [_smarty_vars] =>
                            [_sections] => Array
                                (
                                )
 
                            [_foreach] => Array
                                (
                                )
 
                            [_tag_stack] => Array
                                (
                                )
 
                            [_conf_obj] =>
                            [_config] => Array
                                (
                                    [0] => Array
                                        (
                                            [vars] => Array
                                                (
                                                )
 
                                            [files] => Array
                                                (
                                                )
 
                                        )
 
                                )
 
                            [_smarty_md5] => f8d698aea36fcbead2b9d5359ffca76f
                            [_version] => 2.6.2
                            [_inclusion_depth] => 0
                            [_compile_id] =>
                            [_smarty_debug_id] => SMARTY_DEBUG
                            [_smarty_debug_info] => Array
                                (
                                )
 
                            [_cache_info] => Array
                                (
                                )
 
                            [_file_perms] => 420
                            [_dir_perms] => 505
                            [_reg_objects] => Array
                                (
                                )
 
                            [_plugins] => Array
                                (
                                    [modifier] => Array
                                        (
                                        )
 
                                    [function] => Array
                                        (
                                            [test] => Array
                                                (
                                                    [0] => smarty_test
                                                    [1] => exception_bug.tpl
                                                    [2] => 6
                                                    [3] => 1
                                                    [4] => 1
                                                    [5] =>
                                                )
 
                                        )
 
                                    [block] => Array
                                        (
                                        )
 
                                    [compiler] => Array
                                        (
                                        )
 
                                    [prefilter] => Array
                                        (
                                        )
 
                                    [postfilter] => Array
                                        (
                                        )
 
                                    [outputfilter] => Array
                                        (
                                        )
 
                                    [resource] => Array
                                        (
                                        )
 
                                    [insert] => Array
                                        (
                                        )
 
                                )
 
                            [_cache_serials] => Array
                                (
                                )
 
                            [_cache_include] =>
                            [_cache_including] =>
                        )
 
                )
 
        )
 
    [1] => Array
        (
            [file] => /home/ten_cunha/bug/Smarty-2.6.2/libs/Smarty.class.php
            [line] => 1266
            [args] => Array
                (
                    [0] => /home/ten_cunha/bug/templates_c/%%595^%%595330115^exception_bug.tpl.php
                )
 
            [function] => include
        )
 
    [2] => Array
        (
            [file] => /home/ten_cunha/bug/Smarty-2.6.2/libs/Smarty.class.php
            [line] => 1115
            [function] => fetch
            [class] => Smarty
            [type] => ->
            [args] => Array
                (
                    [0] => exception_bug.tpl
                    [1] =>
                    [2] =>
                    [3] => 1
                )
 
        )
 
    [3] => Array
        (
            [file] => /home/ten_cunha/bug/exception_bug.php
            [line] => 21
            [function] => display
            [class] => Smarty
            [type] => ->
            [args] => Array
                (
                    [0] => exception_bug.tpl
                )
 
        )
 
)
 [2004-05-06 20:00 UTC] derick@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.
 [2004-05-07 23:40 UTC] cunha17 at uol dot com dot br
I can't generate the backtrace. My php(cli) is already compiled with --enable-debug and I recompiled it with only these options:
./configure --enable-debug --enable-cli

When running:
# gdb /usr/local/bin/php core.8971

I get:
GNU gdb Red Hat Linux (5.3.90-0.20030710.41rh)
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

Core was generated by `/usr/local/bin/php exception_bug.php'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libcrypt.so.1...done.
Loaded symbols for /lib/libcrypt.so.1
Reading symbols from /lib/libresolv.so.2...done.
Loaded symbols for /lib/libresolv.so.2
Reading symbols from /lib/tls/libm.so.6...done.
Loaded symbols for /lib/tls/libm.so.6
Reading symbols from /lib/libdl.so.2...done.
Loaded symbols for /lib/libdl.so.2
Reading symbols from /lib/libnsl.so.1...done.
Loaded symbols for /lib/libnsl.so.1
Reading symbols from /usr/lib/libz.so.1...done.
Loaded symbols for /usr/lib/libz.so.1
Reading symbols from /usr/lib/libxml2.so.2...done.
Loaded symbols for /usr/lib/libxml2.so.2
Reading symbols from /lib/tls/libpthread.so.0...done.
Loaded symbols for /lib/tls/libpthread.so.0
Reading symbols from /lib/tls/libc.so.6...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
0x00000000 in ?? ()

The backtrace command returns:

(gdb) bt
#0  0x00000000 in ?? ()

I don't know what else I can do. Any hints ?

Cristiano Duarte
 [2004-05-19 15:25 UTC] cunha17 at uol dot com dot br
Using the gdb's "next" command, I could get an useful backtrace:

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt
#0  0x00000000 in ?? ()
#1  0x0819c798 in execute (op_array=0x4076e378, tsrm_ls=0x8203200)
    at /usr/src/zend2/php-src/Zend/zend_execute.c:1391
#2  0x0819fd9b in zend_do_fcall_common_helper (execute_data=0xbfffd110,
    opline=0x4076e174, op_array=0x4076f0a0, tsrm_ls=0x8203200)
    at /usr/src/zend2/php-src/Zend/zend_execute.c:2728
#3  0x0819c798 in execute (op_array=0x4076f0a0, tsrm_ls=0x8203200)
    at /usr/src/zend2/php-src/Zend/zend_execute.c:1391
#4  0x0819fd9b in zend_do_fcall_common_helper (execute_data=0xbfffd340,
    opline=0x40505dfc, op_array=0x40505520, tsrm_ls=0x8203200)
    at /usr/src/zend2/php-src/Zend/zend_execute.c:2728
#5  0x0819c798 in execute (op_array=0x40505520, tsrm_ls=0x8203200)
    at /usr/src/zend2/php-src/Zend/zend_execute.c:1391
#6  0x081803ec in zend_execute_scripts (type=8, tsrm_ls=0x8203200, retval=0x0,
    file_count=3) at /usr/src/zend2/php-src/Zend/zend.c:1058
#7  0x0814a191 in php_execute_script (primary_file=0xbffff710,
    tsrm_ls=0x8203200) at /usr/src/zend2/php-src/main/main.c:1630
#8  0x081a7f8a in main (argc=2, argv=0xbffff794)
    at /usr/src/zend2/php-src/sapi/cli/php_cli.c:943
#9  0x403d0a67 in __libc_start_main () from /lib/i686/libc.so.6
 [2005-01-18 22:50 UTC] cunha17 at gmail dot com
This BUG is not present in current CVS anymore.
Thanx.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Nov 25 14:00:01 2025 UTC