dreamsxin / cphalcon7

Dao7 - Web framework for PHP,QQ群 316911641 & 515414530
https://dreamsxin.github.io/phalcon7-docs/
247 stars 66 forks source link

Segmentation fault on Phalcon\Aop\Joinpoint::addAfterReturning #496

Closed sergeyklay closed 4 years ago

sergeyklay commented 4 years ago
<?php
// manual.php

use Phalcon\Aop;
use Phalcon\Aop\Joinpoint;

function doStuffException() {
    echo __FUNCTION__;
    throw new Exception('Exception doStuffException');
}

$interceptor = new Aop();
$interceptor->addAfterReturning('doStuff*()', function () {
    echo '[after]', PHP_EOL;
});

try {
    doStuffException();
} catch (Exception $e) {
    echo '[caught]', PHP_EOL;
}
$ php -d phalcon.aop.enable_aop=1 -d extension=ext/modules/phalcon.so manual.php
php: /home/klay/src/php/source/7.4.0/ext/pcre/php_pcre.c:931: php_pcre_create_match_data: Assertion `NULL != re' failed
0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
1  0x00007ffff4cc4535 in __GI_abort () at abort.c:79
2  0x00007ffff4cc440f in __assert_fail_base (fmt=0x7ffff4e26ee0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55555602caa4 "NULL != re", file=0x55555602c368 "/home/klay/src/php/source/7.4.0/ext/pcre/php_pcre.c", line=931, function=<optimized out>) at assert.c:92
3  0x00007ffff4cd2102 in __GI___assert_fail (assertion=0x55555602caa4 "NULL != re", file=0x55555602c368 "/home/klay/src/php/source/7.4.0/ext/pcre/php_pcre.c", line=931, function=0x55555602d1d0 <__PRETTY_FUNCTION__.21423> "php_pcre_create_match_data") at assert.c:101
4  0x000055555584d6c4 in php_pcre_create_match_data (capture_count=0, re=0x0) at /home/klay/src/php/source/7.4.0/ext/pcre/php_pcre.c:931
5  0x00007ffff1cacf48 in pointcut_match_zend_function (pc=0x7ffff3e6f3c0, ex=0x7ffff3e140f0) at /home/klay/work/cphalcon7/ext/aop.c:288
6  0x00007ffff1cad128 in calculate_function_pointcuts (ex=0x7ffff3e140f0) at /home/klay/work/cphalcon7/ext/aop.c:343
7  0x00007ffff1cada54 in get_cache_func (ex=0x7ffff3e140f0) at /home/klay/work/cphalcon7/ext/aop.c:523
8  0x00007ffff1cae9d9 in func_pointcut_and_execute (ex=0x7ffff3e140f0) at /home/klay/work/cphalcon7/ext/aop.c:805
9  0x00007ffff1caef7c in phalcon_aop_execute_ex (ex=0x7ffff3e140f0) at /home/klay/work/cphalcon7/ext/aop.c:900
10 0x00007ffff1cbbc76 in async_execute_ex (exec=0x7ffff3e140f0) at /home/klay/work/cphalcon7/ext/async/core.c:51
11 0x0000555555df8c29 in ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER () at /home/klay/src/php/source/7.4.0/Zend/zend_vm_execute.h:1601
12 0x0000555555e5cd49 in execute_ex (ex=0x7ffff3e14020) at /home/klay/src/php/source/7.4.0/Zend/zend_vm_execute.h:53571
13 0x00007ffff1caef43 in phalcon_aop_execute_ex (ex=0x7ffff3e14020) at /home/klay/work/cphalcon7/ext/aop.c:896
14 0x00007ffff1cbbaca in execute_root (exec=0x7ffff3e14020) at /home/klay/work/cphalcon7/ext/async/core.c:30
15 0x00007ffff1cbbc61 in async_execute_ex (exec=0x7ffff3e14020) at /home/klay/work/cphalcon7/ext/async/core.c:49
16 0x0000555555e60e92 in zend_execute (op_array=0x7ffff3e86400, return_value=0x0) at /home/klay/src/php/source/7.4.0/Zend/zend_vm_execute.h:57651
17 0x0000555555d82ad2 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /home/klay/src/php/source/7.4.0/Zend/zend.c:1663
18 0x0000555555ccf528 in php_execute_script (primary_file=0x7fffffffd920) at /home/klay/src/php/source/7.4.0/main/main.c:2619
19 0x0000555555e6396c in do_cli (argc=6, argv=0x555556baad40) at /home/klay/src/php/source/7.4.0/sapi/cli/php_cli.c:961
20 0x0000555555e64a6f in main (argc=6, argv=0x555556baad40) at /home/klay/src/php/source/7.4.0/sapi/cli/php_cli.c:1352
$ php -v
PHP 7.4.0 (cli) (built: Nov 28 2019 20:49:56) ( ZTS DEBUG )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies

Git commit: 40c0c21b73c15dccf947a015a2dd0c3a5ee9a432

sergeyklay commented 4 years ago

Possible fix:

diff --git a/ext/aop.c b/ext/aop.c
index 0bbb40003..df38204d4 100644
--- a/ext/aop.c
+++ b/ext/aop.c
@@ -149,6 +149,10 @@ static int pointcut_match_zend_class_entry(phalcon_aop_pointcut *pc, zend_class_
 {
        int i, matches;

+       if (pc == NULL || pc->re_class == NULL) {
+               return 0;
+       }
+
 #if PHP_VERSION_ID >= 70300
        pcre2_match_data *match_data = php_pcre_create_match_data(0, pc->re_class);
        if (NULL == match_data) {
@@ -222,7 +226,7 @@ static int pointcut_match_zend_class_entry(phalcon_aop_pointcut *pc, zend_class_
 #endif
                ce = ce->parent;
        }
-       
+
 #if PHP_VERSION_ID >= 70300
        php_pcre_free_match_data(match_data);
 #endif
@@ -285,7 +289,7 @@ static int pointcut_match_zend_function(phalcon_aop_pointcut *pc, zend_execute_d
        if (pc->method_jok) {
                int matches;
 #if PHP_VERSION_ID >= 70300
-               pcre2_match_data *match_data = php_pcre_create_match_data(0, pc->re_class);
+               pcre2_match_data *match_data = php_pcre_create_match_data(0, pc->re_method);
                if (NULL == match_data) {
                        return 0;
                }