|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-01-07 10:10 UTC] nick dot telford at gmail dot com
Description:
------------
When submitting a query to Sphinx, the client segfaults if the query contains any closing parentheses with no associated opening parentheses.
Example queries that work as expected:
something
(something)
(something
Example queries that cause a segfault:
something)
(something))
gdb backtrace (attained through apache):
Program received signal SIGSEGV, Segmentation fault.
php_sphinx_result_to_array (c=0x2ad90ac2c390, result=0x2ad90a9bf230, array=0x7fff22366cc0) at /var/tmp/sphinx/sphinx.c:179
179 /var/tmp/sphinx/sphinx.c: No such file or directory.
in /var/tmp/sphinx/sphinx.c
(gdb) bt
#0 php_sphinx_result_to_array (c=0x2ad90ac2c390, result=0x2ad90a9bf230, array=0x7fff22366cc0) at /var/tmp/sphinx/sphinx.c:179
#1 0x00002ad9095fc4d3 in zim_SphinxClient_runQueries (ht=<value optimized out>, return_value=0x2ad90abd6930, return_value_ptr=<value optimized out>, this_ptr=<value optimized out>, return_value_used=<value optimized out>) at /var/tmp/sphinx/sphinx.c:1344
#2 0x00002ad9077ccb51 in ?? () from /usr/lib64/php/modules/dbg-php-5.2.so
#3 0x00002ad901e53a43 in ?? () from /etc/httpd/modules/libphp5.so
#4 0x00002ad901e4624c in execute () from /etc/httpd/modules/libphp5.so
#5 0x00002ad9077cfdb5 in ?? () from /usr/lib64/php/modules/dbg-php-5.2.so
#6 0x00002ad901e53684 in ?? () from /etc/httpd/modules/libphp5.so
#7 0x00002ad901e4624c in execute () from /etc/httpd/modules/libphp5.so
#8 0x00002ad9077cfdb5 in ?? () from /usr/lib64/php/modules/dbg-php-5.2.so
#9 0x00002ad901e53684 in ?? () from /etc/httpd/modules/libphp5.so
#10 0x00002ad901e4624c in execute () from /etc/httpd/modules/libphp5.so
#11 0x00002ad9077cfdb5 in ?? () from /usr/lib64/php/modules/dbg-php-5.2.so
#12 0x00002ad901e53684 in ?? () from /etc/httpd/modules/libphp5.so
#13 0x00002ad901e4624c in execute () from /etc/httpd/modules/libphp5.so
#14 0x00002ad9077cfdb5 in ?? () from /usr/lib64/php/modules/dbg-php-5.2.so
#15 0x00002ad901e53684 in ?? () from /etc/httpd/modules/libphp5.so
#16 0x00002ad901e4624c in execute () from /etc/httpd/modules/libphp5.so
#17 0x00002ad9077cfdb5 in ?? () from /usr/lib64/php/modules/dbg-php-5.2.so
#18 0x00002ad901e267e3 in zend_execute_scripts () from /etc/httpd/modules/libphp5.so
#19 0x00002ad901de6878 in php_execute_script () from /etc/httpd/modules/libphp5.so
#20 0x00002ad901ea937d in ?? () from /etc/httpd/modules/libphp5.so
#21 0x00002ad8fa799a4a in ap_run_handler () from /usr/sbin/httpd
#22 0x00002ad8fa79cec2 in ap_invoke_handler () from /usr/sbin/httpd
#23 0x00002ad8fa7a776a in ap_internal_redirect () from /usr/sbin/httpd
#24 0x00002ad9015fcbc0 in ?? () from /etc/httpd/modules/mod_rewrite.so
#25 0x00002ad8fa799a4a in ap_run_handler () from /usr/sbin/httpd
#26 0x00002ad8fa79cec2 in ap_invoke_handler () from /usr/sbin/httpd
#27 0x00002ad8fa7a7918 in ap_process_request () from /usr/sbin/httpd
#28 0x00002ad8fa7a4b50 in ?? () from /usr/sbin/httpd
#29 0x00002ad8fa7a0cb2 in ap_run_process_connection () from /usr/sbin/httpd
#30 0x00002ad8fa7ab859 in ?? () from /usr/sbin/httpd
#31 0x00002ad8fa7aba59 in ?? () from /usr/sbin/httpd
#32 0x00002ad8fa7ac577 in ap_mpm_run () from /usr/sbin/httpd
#33 0x00002ad8fa786e48 in main () from /usr/sbin/httpd
Reproduce code:
---------------
$sphinx = new SphinxClient();
$sphinx->setSetver('localhost', 3312);
$sphinx->addQuery('something)');
$results = $sphinx->runQueries();
var_dump($results);
// SphinxClient::query() has the same problem, but out code uses batched queries, so that is what I've used in the reproduce code
Expected result:
----------------
array(
)
(or an array of results, if you happen to have a dataset that will match that query)
Actual result:
--------------
segmentation fault
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 14:00:01 2025 UTC |
My test script is missing something vital, should be: <?php $sphinx = new SphinxClient(); $sphinx->setServer('localhost', 3312); $sphinx->setMatchMode(SPH_MATCH_EXTENDED2); $sphinx->addQuery('something)'); $results = $sphinx->runQueries(); var_dump($results); It's only caused if the match mode is set to SPH_MATCH_EXTENDED2. I believe you're right and that this is a libsphinxclient issue. Unless I hear otherwise from you, I'm going to flag this up as an issue with them. Thanks for your help, the following is a full backtrace, taken as instructed: [Thread debugging using libthread_db enabled] [New Thread 0x2b76c199ff50 (LWP 11326)] Program received signal SIGSEGV, Segmentation fault. 0x00000000005e3eae in php_sphinx_result_to_array (c=0x2b76c52079e0, result=0x7bdbd18, array=0x7fffb8b84c60) at /home/alex/build/php-5.2.11_tm/ext/sphinx/sphinx.c:179 179 add_next_index_string(tmp, result->fields[i], 1); (gdb) bt full #0 0x00000000005e3eae in php_sphinx_result_to_array (c=0x2b76c52079e0, result=0x7bdbd18, array=0x7fffb8b84c60) at /home/alex/build/php-5.2.11_tm/ext/sphinx/sphinx.c:179 tmp = (zval *) 0x7c9d788 tmp_element = (zval *) 0x6fe9bb sub_element = (zval *) 0x7bb91b8 sub_sub_element = (zval *) 0x722e50 i = 0 j = 0 #1 0x00000000005e8b95 in zim_SphinxClient_runQueries (ht=0, return_value=0x7bb0f88, return_value_ptr=0x0, this_ptr=0x7bb0f18, return_value_used=1) at /home/alex/build/php-5.2.11_tm/ext/sphinx/sphinx.c:1344 c = (php_sphinx_client *) 0x2b76c52079e0 results = (sphinx_result *) 0x7bdbd18 i = 0 num_results = 1 single_result = (zval *) 0x7bb91b8 #2 0x000000000074892a in zend_do_fcall_common_helper_SPEC (execute_data=0x7fffb8b85150) at /home/alex/build/php-5.2.11_tm/Zend/zend_vm_execute.h:200 return_reference = 0 '\0' opline = (zend_op *) 0x2b76c51f6fd0 original_return_value = (zval **) 0x71b393 current_scope = (zend_class_entry *) 0x7c61e00 current_this = (zval *) 0x7bb0f18 return_value_used = 1 should_change_scope = 1 '\001' ctor_opline = (zend_op *) 0x74b069 #3 0x00000000007496d5 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER (execute_data=0x7fffb8b85150) at /home/alex/build/php-5.2.11_tm/Zend/zend_vm_execute.h:322 No locals. #4 0x00000000007483cb in execute (op_array=0x2b76c5207600) at /home/alex/build/php-5.2.11_tm/Zend/zend_vm_execute.h:92 execute_data = {opline = 0x2b76c51f6fd0, function_state = {function_symbol_table = 0x0, function = 0x7b683e0, reserved = {0x7bb9650, 0x7fffb8b85190, 0xc0cd4f98a04f5e18, 0x1807bb1ba8}}, fbc = 0x7b683e0, op_array = 0x2b76c5207600, object = 0x7bb0f18, Ts = 0x7fffb8b84dd0, CVs = 0x7fffb8b84d90, original_in_execution = 1 '\001', symbol_table = 0x7bea8e8, prev_execute_data = 0x7fffb8b85d50, old_error_reporting = 0x0} #5 0x0000000000748ab9 in zend_do_fcall_common_helper_SPEC (execute_data=0x7fffb8b85d50) at /home/alex/build/php-5.2.11_tm/Zend/zend_vm_execute.h:234 opline = (zend_op *) 0x7bb2d48 original_return_value = (zval **) 0x7fffb8b85e48 current_scope = (zend_class_entry *) 0x0 current_this = (zval *) 0x0 return_value_used = 1 should_change_scope = 1 '\001' ctor_opline = (zend_op *) 0x326161bbc0 #6 0x00000000007496d5 in ZEND_DO_FCALL_BY_NAME_SPEC_HANDLER (execute_data=0x7fffb8b85d50) at /home/alex/build/php-5.2.11_tm/Zend/zend_vm_execute.h:322 No locals. #7 0x00000000007483cb in execute (op_array=0x7baf1d0) at /home/alex/build/php-5.2.11_tm/Zend/zend_vm_execute.h:92 execute_data = {opline = 0x7bb2d48, function_state = {function_symbol_table = 0x7bea8e8, function = 0x2b76c5207600, reserved = {0x7baf310, 0x7fffb8b85db0, 0x712ae3, 0x0}}, fbc = 0x2b76c5207600, op_array = 0x7baf1d0, object = 0x7bb0f18, Ts = 0x7fffb8b85320, CVs = 0x7fffb8b852e0, original_in_execution = 0 '\0', symbol_table = 0xce2848, prev_execute_data = 0x0, old_error_reporting = 0x0} #8 0x000000000071f47a in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /home/alex/build/php-5.2.11_tm/Zend/zend.c:1134 files = {{gp_offset = 40, fp_offset = 48, overflow_arg_area = 0x7fffb8b85f60, reg_save_area = 0x7fffb8b85ea0}} i = 1 file_handle = (zend_file_handle *) 0x7fffb8b883a0 orig_op_array = (zend_op_array *) 0x0 orig_retval_ptr_ptr = (zval **) 0x0 local_retval = (zval *) 0x0 #9 0x00000000006c48d1 in php_execute_script (primary_file=0x7fffb8b883a0) at /home/alex/build/php-5.2.11_tm/main/main.c:2020 realfile = "/var/www/tweetmeme4/public/index.php\000\177\000\000���", '\0' <repeats 13 times>, "�\205���\177", '\0' <repeats 26 times>, "\025�@a2\000\000\000\001", '\0' <repeats 31 times>, "hB\200a2\000\000\000��aa2\000\000\000�p���\177\000\000\222(Aa2\000\000\000�Qz\000\000\000\000\000\000�\237\000\000\000\000\000\220A�\a\000\000\000\000Z�r\000\000\000\000\000\200\027�a2\000\000\000\004\000\000\000\000\000\000\000\200\027�a2\000\000\000�\021\206a2\000\000\000��aa2\000\000\000\000Rz\000\000\000\000\000"... __orig_bailout = (jmp_buf *) 0x7fffb8b88210 __bailout = {{__jmpbuf = {216382159808, -8268687197646134416, 0, 140736292488640, 0, 0, -8268687197646111424, -8268671372701490093}, __mask_was_saved = 0, __saved_mask = {__val = {140736292487232, 140736292487232, 7334446, 129857264, 3099099248, 0, 2452426326016, 10666792, 129688824, 140736292487504, 8018297, 10666792, 524, 0, 0, 3}}}} prepend_file_p = (zend_file_handle *) 0x0 append_file_p = (zend_file_handle *) 0x0 prepend_file = {type = 0 '\0', filename = 0x0, opened_path = 0x0, handle = {fd = 0, fp = 0x0, stream = {handle = 0x0, reader = 0, closer = 0, fteller = 0, interactive = 0}}, free_filename = 0 '\0'} append_file = {type = 0 '\0', filename = 0x0, opened_path = 0x0, handle = {fd = 0, fp = 0x0, stream = {handle = 0x0, reader = 0, closer = 0, fteller = 0, interactive = 0}}, free_filename = 0 '\0'} old_cwd = 0x7fffb8b85f80 "" retval = 0 #10 0x00000000007a69a5 in main (argc=2, argv=0x7fffb8b885c8) at /home/alex/build/php-5.2.11_tm/sapi/cli/php_cli.c:1162 __orig_bailout = (jmp_buf *) 0x0 ---Type <return> to continue, or q <return> to quit--- __bailout = {{__jmpbuf = {216382159808, -8268687197646133568, 0, 140736292488640, 0, 0, -8268687197646134464, -8268671372700828223}, __mask_was_saved = 0, __saved_mask = {__val = {140736292487808, 4287062190, 140736292488208, 140736292488232, 216384158344, 0, 47789054223584, 47789052002304, 216421996075, 216384207904, 216421919048, 4294967296, 4294968490, 140736292488272, 216379984919, 140736292488288}}}} exit_status = 0 c = -1 file_handle = {type = 2 '\002', filename = 0x7fffb8b88c0c "index.php", opened_path = 0x0, handle = {fd = 129856336, fp = 0x7bd7350, stream = {handle = 0x7bd7350, reader = 0x738e44 <zend_stream_stdio_reader>, closer = 0x738e70 <zend_stream_stdio_closer>, fteller = 0x738e97 <zend_stream_stdio_fteller>, interactive = 0}}, free_filename = 0 '\0'} behavior = 1 reflection_what = 0x0 orig_optind = 1 orig_optarg = 0x0 arg_free = 0x7fffb8b88c0c "index.php" arg_excp = (char **) 0x7fffb8b885d0 script_file = 0x7fffb8b88c0c "index.php" interactive = 0 module_started = 1 request_started = 1 lineno = 1 exec_direct = 0x0 exec_run = 0x0 exec_begin = 0x0 exec_end = 0x0 param_error = 0x0 hide_argv = 0 ini_entries_len = 110Requested values: (gdb) p *result $1 = {error = 0xcc38de7 "index <index name>: syntax error, unexpected ')', expecting $end near ')'", warning = 0x0, status = 1, num_fields = 1025534068, fields = 0x0, num_attrs = 1953702944, attr_names = 0x0, attr_types = 0x0, num_matches = 1965301800, values_pool = 0x0, total = 538970683, total_found = 1868963872, time_msec = 606609522, num_words = 540876905, words = 0x0} (gdb) p i $2 = 1 (gdb) p result->fields[i] Cannot access memory at address 0x8 (gdb) p result->fields $3 = (char **) 0x0 Note: <index name> is in place of the name of the real index for obfuscation purposes. Seems that the client is returning a valid error state to me, I'm not sure if that's expected. I'm assuming that the syntax error is in the query, and not the index configuration. Nevertheless, I will check out index config to see if there's anything there that might explain it.