SeasX / SeasLog

An effective,fast,stable log extension for PHP.http://pecl.php.net/package/SeasLog http://php.net/SeasLog
http://seasx.github.io/SeasLog/
Other
1.2k stars 276 forks source link

fix core dump #284

Closed 769344359 closed 4 years ago

769344359 commented 4 years ago

core dump 堆栈

#0  strlen () at ../sysdeps/x86_64/strlen.S:106
#1  0x00007f1fcb9c9601 in seaslog_clear_request_variable () at /home/dinosaur/SeasLog/src/Request.c:223
#2  0x00007f1fcb9c52e4 in seaslog_template_formatter (xbuf=0x7ffe611d33e0, generate_type=2, fmt=0x7f1fcc6810a4 "F", level=0x7f1fcb9ca6f8 "exception", ap=0x7ffe611d33f0) at /home/dinosaur/SeasLog/src/TemplateFormatter.c:293
#3  0x00007f1fcb9c4c62 in seaslog_spprintf (pbuf=0x7ffe611d3518, generate_type=2, level=0x7f1fcb9ca6f8 "exception", max_len=0) at /home/dinosaur/SeasLog/src/TemplateFormatter.c:131
#4  0x00007f1fcb9c5f8f in appender_handle_tcp_udp (message=0x7f1fc2fb1ce0 "aaa", message_len=3, level=0x7f1fcb9ca6f8 "exception", level_int=3, logger=0x7f1fcc67ca50, ce=0x24e29b0) at /home/dinosaur/SeasLog/src/Appender.c:115
#5  0x00007f1fcb9c615d in appender_handle_file (
    message=0x7f1fcb9cb238 "J+bi0HAHmIYrbMaB0I9yKHKjQMiBxaD4G3wTwESPl/x1otR8O90KWpdQAQdVt/OFdn2m5yPUDUfc0QIOihynpD0Q4gNjAzWs5YL9xdbkVOd96vkHO2ZFo2FH9/nHbIs63ks7Zk6gSZzGs/paPjPa8tYW/S0rE9cUH2/GhkZhhpvlJwy+F2fHpogn82Jk+6Km6vzH5bic"..., message_len=0, level=0x7f1fcb9c615d <appender_handle_file+251> "\211E܋E؍H\001H\213U\340H\213E\350H\213}\250\213u\334I\211\370H\211\307\350\333\374\377\377\203\370\377uMH\213E\340A\270", level_int=1, 
    logger=0x7ffe611d3580, ce=0x62303514974fee00) at /home/dinosaur/SeasLog/src/Appender.c:144
#6  0x00007f1fcb9bf077 in seaslog_log_context_ex (argc=1, check_argc=1, level=0x7f1fcb9ca6f8 "exception", level_int=3, message=0x7f1fc2fb1ce0 "aaa", message_len=3, context=0x0, 
    module=0x7f1fcb9cb238 "J+bi0HAHmIYrbMaB0I9yKHKjQMiBxaD4G3wTwESPl/x1otR8O90KWpdQAQdVt/OFdn2m5yPUDUfc0QIOihynpD0Q4gNjAzWs5YL9xdbkVOd96vkHO2ZFo2FH9/nHbIs63ks7Zk6gSZzGs/paPjPa8tYW/S0rE9cUH2/GhkZhhpvlJwy+F2fHpogn82Jk+6Km6vzH5bic"..., module_len=0, seaslog_ce=0x24e29b0) at /home/dinosaur/SeasLog/seaslog.c:374
#7  0x00007f1fcb9bf206 in seaslog_log_by_level_common_ex (argc=1, check_argc=1, level=0x7f1fcb9ca6f8 "exception", level_int=3, messages=0x7f1fcc61e1d0, context=0x0, 
    logger_str=0x7f1fcb9cb238 "J+bi0HAHmIYrbMaB0I9yKHKjQMiBxaD4G3wTwESPl/x1otR8O90KWpdQAQdVt/OFdn2m5yPUDUfc0QIOihynpD0Q4gNjAzWs5YL9xdbkVOd96vkHO2ZFo2FH9/nHbIs63ks7Zk6gSZzGs/paPjPa8tYW/S0rE9cUH2/GhkZhhpvlJwy+F2fHpogn82Jk+6Km6vzH5bic"..., logger_len=0, seaslog_ce=0x24e29b0) at /home/dinosaur/SeasLog/seaslog.c:411
#8  0x00007f1fcb9bf3bc in seaslog_log_by_level_common (execute_data=0x7f1fcc61e180, return_value=0x7ffe611d38f0, level=0x7f1fcb9ca6f8 "exception", level_int=3) at /home/dinosaur/SeasLog/seaslog.c:499
#9  0x00007f1fcb9c0c1a in zim_SEASLOG_RES_NAME_log (execute_data=0x7f1fcc61e1d0, return_value=0x100000000) at /home/dinosaur/SeasLog/seaslog.c:1153
#10 0x0000000000a1cff8 in zend_call_function (fci=0x7ffe611d3930, fci_cache=0x7ffe611d3900) at /home/dinosaur/Downloads/php-7.2.2/Zend/zend_execute_API.c:833
#11 0x000000000083bcb3 in zif_forward_static_call_array (execute_data=0x7f1fcc61e110, return_value=0x7ffe611d39b0) at /home/dinosaur/Downloads/php-7.2.2/ext/standard/basic_functions.c:4975
#12 0x0000000000aae986 in ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER () at /home/dinosaur/Downloads/php-7.2.2/Zend/zend_vm_execute.h:573
#13 0x0000000000b4295e in execute_ex (ex=0x7f1fcc61e030) at /home/dinosaur/Downloads/php-7.2.2/Zend/zend_vm_execute.h:59731
#14 0x0000000000b47d9d in zend_execute (op_array=0x7f1fcc682b00, return_value=0x0) at /home/dinosaur/Downloads/php-7.2.2/Zend/zend_vm_execute.h:63760
#15 0x0000000000a3afe0 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /home/dinosaur/Downloads/php-7.2.2/Zend/zend.c:1496
#16 0x000000000098c749 in php_execute_script (primary_file=0x7ffe611d6090) at /home/dinosaur/Downloads/php-7.2.2/main/main.c:2590
#17 0x0000000000b4b2a5 in do_cli (argc=2, argv=0x2322d80) at /home/dinosaur/Downloads/php-7.2.2/sapi/cli/php_cli.c:1011
#18 0x0000000000b4c491 in main (argc=2, argv=0x2322d80) at /home/dinosaur/Downloads/php-7.2.2/sapi/cli/php_cli.c:1404

const char *ret; 没有被赋值过,然后strlen(ret)访问了只读地址导致core dump

769344359 commented 4 years ago

我自己跑make test 是通过测试的

=====================================================================
TIME START 2019-12-16 16:43:18
=====================================================================
PASS Check for seaslog presence [tests/001.phpt]
PASS Check for seaslog_get_version [tests/002.phpt]
PASS Check for seaslog_get_author [tests/003.phpt]
PASS Check for setBasePath [tests/004.phpt]
PASS Check for setLogger [tests/005.phpt]
PASS Check for setDatetimeFormat [tests/006.phpt]
PASS Check for setRequestID [tests/007.phpt]
PASS Check for SeasLog log functions with one parameter. [tests/008.phpt]
PASS Check for SeasLog log functions with two parameters. [tests/009.phpt]
PASS Check for SeasLog log functions with three parameters. [tests/010.phpt]
PASS Check for SeasLog::log() function with two parameters. [tests/011.phpt]
PASS Check for SeasLog::log() function with three parameters. [tests/012.phpt]
PASS Check for SeasLog::log() function with four parameters. [tests/013.phpt]
PASS Check for SeasLog::getBuffer() function. [tests/014.phpt]
PASS Check for SeasLog::closeLoggerStream() function. [tests/015.phpt]
FAIL Check for SeasLog::analyzerCount() function. [tests/016.phpt]
FAIL Check for SeasLog::analyzerDetail() function. [tests/017.phpt]
PASS Check for new SeasLog(). [tests/018.phpt]
PASS Check for SeasLog::setRequestVariable() and SeasLog::getRequestVariable() function. [tests/019.phpt]
PASS Check for SeasLog::setLogger() function. [tests/020.phpt]
PASS Check for SeasLog::getBufferCount() function. [tests/021.phpt]
PASS pr 284 [tests/022.phpt]
=====================================================================
TIME END 2019-12-16 16:43:19

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :   30
---------------------------------------------------------------------

Number of tests :   22                22
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    2 (  9.1%) (  9.1%)
Expected fail   :    0 (  0.0%) (  0.0%)
Tests passed    :   20 ( 90.9%) ( 90.9%)
---------------------------------------------------------------------
Time taken      :    1 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Check for SeasLog::analyzerCount() function. [tests/016.phpt]
Check for SeasLog::analyzerDetail() function. [tests/017.phpt]
=====================================================================
769344359 commented 4 years ago

php 5.6

(gdb) bt
#0  get_code_filename_line (result=0x7ffffffe9fc0) at /home/ubuntu/SeasLog/src/Request.c:329
#1  0x00007ffff3eaa30e in seaslog_template_formatter (xbuf=0x7fffffffa050, generate_type=2, fmt=0x7ffff7fdc984 "F", level=0x7ffff3eb0a00 "ERROR", ap=0x7fffffffa070)
    at /home/ubuntu/SeasLog/src/TemplateFormatter.c:330
#2  0x00007ffff3ea99b2 in seaslog_spprintf (pbuf=0x7fffffffa1a8, generate_type=2, level=0x7ffff3eb0a00 "ERROR", max_len=0) at /home/ubuntu/SeasLog/src/TemplateFormatter.c:157
#3  0x00007ffff3eab5d0 in appender_handle_file (message=0x7ffff7ec89f8 "aaa", message_len=3, level=0x7ffff3eb0a00 "ERROR", level_int=3, logger=0x7ffff7fdcb60, ce=0x55555640eff0)
    at /home/ubuntu/SeasLog/src/Appender.c:144
#4  0x00007ffff3eab79e in seaslog_log_ex (argc=1, level=0x7ffff3eb0a00 "ERROR", level_int=3, message=0x7ffff7ec89f8 "aaa", message_len=3, module=0x7ffff3eb1540 "", module_len=0, 
    ce=0x55555640eff0) at /home/ubuntu/SeasLog/src/Appender.c:190
#5  0x00007ffff3ea32ca in seaslog_log_context_ex (argc=1, check_argc=1, level=0x7ffff3eb0a00 "ERROR", level_int=3, message=0x7ffff7ec89f8 "aaa", message_len=3, context=0x0, 
    module=0x7ffff3eb1540 "", module_len=0, seaslog_ce=0x55555640eff0) at /home/ubuntu/SeasLog/seaslog.c:384
#6  0x00007ffff3ea3614 in seaslog_log_by_level_common_ex (argc=1, check_argc=1, level=0x7ffff3eb0a00 "ERROR", level_int=3, messages=0x7ffff7fdd038, context=0x0, 
    logger_str=0x7ffff3eb1540 "", logger_len=0, seaslog_ce=0x55555640eff0) at /home/ubuntu/SeasLog/seaslog.c:456
#7  0x00007ffff3ea37b1 in seaslog_log_by_level_common (ht=1, return_value=0x7ffff7fde8d8, return_value_ptr=0x7fffffffa578, this_ptr=0x0, return_value_used=1, 
    level=0x7ffff3eb0a00 "ERROR", level_int=3) at /home/ubuntu/SeasLog/seaslog.c:532
#8  0x00007ffff3ea533c in zim_SEASLOG_RES_NAME_error (ht=1, return_value=0x7ffff7fde8d8, return_value_ptr=0x7fffffffa578, this_ptr=0x0, return_value_used=1)
    at /home/ubuntu/SeasLog/seaslog.c:1228
#9  0x0000555555a62b85 in zend_call_function (fci=0x7fffffffa5b0, fci_cache=0x7fffffffa580) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_execute_API.c:850
#10 0x0000555555933b6a in zif_forward_static_call_array (ht=2, return_value=0x7ffff7fe0560, return_value_ptr=0x7ffff7fa6328, this_ptr=0x0, return_value_used=0)
    at /home/ubuntu/php-src-PHP-5.6.40/ext/standard/basic_functions.c:4934
#11 0x0000555555ac0c81 in zend_do_fcall_common_helper_SPEC (execute_data=0x7ffff7fa6360) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_vm_execute.h:558
#12 0x0000555555ac675d in ZEND_DO_FCALL_SPEC_CONST_HANDLER (execute_data=0x7ffff7fa6360) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_vm_execute.h:2602
#13 0x0000555555ac02e7 in execute_ex (execute_data=0x7ffff7fa6360) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_vm_execute.h:363
#14 0x0000555555ac0370 in zend_execute (op_array=0x7ffff7fe0fa8) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_vm_execute.h:388
#15 0x0000555555a629c1 in zend_call_function (fci=0x7fffffffa950, fci_cache=0x7fffffffa920) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_execute_API.c:831
#16 0x0000555555a9acb8 in zend_call_method (object_pp=0x0, obj_ce=0x7ffff7fdfe90, fn_proxy=0x7ffff7fdfff0, function_name=0x555555f5143e "__callstatic", function_name_len=12, 
    retval_ptr_ptr=0x7fffffffaa28, param_count=2, arg1=0x7ffff7fdfd60, arg2=0x7ffff7fe17d8) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_interfaces.c:97
#17 0x0000555555ab63e8 in zend_std_callstatic_user_call (ht=1, return_value=0x7ffff7fdcf48, return_value_ptr=0x7ffff7fa61f8, this_ptr=0x0, return_value_used=0)
    at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_object_handlers.c:1145
#18 0x0000555555ac0c81 in zend_do_fcall_common_helper_SPEC (execute_data=0x7ffff7fa6250) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_vm_execute.h:558
#19 0x0000555555ac1455 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER (execute_data=0x7ffff7fa6250) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_vm_execute.h:693
#20 0x0000555555ac02e7 in execute_ex (execute_data=0x7ffff7fa6250) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_vm_execute.h:363
#21 0x0000555555ac0370 in zend_execute (op_array=0x7ffff7fdde78) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend_vm_execute.h:388
#22 0x0000555555a789d2 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /home/ubuntu/php-src-PHP-5.6.40/Zend/zend.c:1341
#23 0x00005555559d975e in php_execute_script (primary_file=0x7fffffffd050) at /home/ubuntu/php-src-PHP-5.6.40/main/main.c:2613
#24 0x0000555555b35441 in do_cli (argc=2, argv=0x555556289ae0) at /home/ubuntu/php-src-PHP-5.6.40/sapi/cli/php_cli.c:998
#25 0x0000555555b367a5 in main (argc=2, argv=0x555556289ae0) at /home/ubuntu/php-src-PHP-5.6.40/sapi/cli/php_cli.c:1382

ptr->op_array也是空的

(gdb) p ptr->op_array 
$6 = (zend_op_array *) 0x0