php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53022 Segfault in php-cgi after executing a script with syntax error
Submitted: 2010-10-08 10:44 UTC Modified: 2013-02-18 00:34 UTC
Votes:5
Avg. Score:4.4 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: hightman at twomice dot net Assigned:
Status: No Feedback Package: Reproducible crash
PHP Version: 5.3.3 OS: FreeBSD Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: hightman at twomice dot net
New email:
PHP Version: OS:

 

 [2010-10-08 10:44 UTC] hightman at twomice dot net
Description:
------------
Every php-cgi/fastcgi process was designed to handle multi requests, but after executing a script file which has syntax error, the php-cgi will crash when next request comming in.

Test script:
---------------
1. start the php-cgi:  
   php-cgi -b /tmp/php53/php-cgi.sock
2. simple test script with syntax error:
   <?php $++; ?>
3. run twice requests to this script

Actual result:
--------------
The first time, request was handled normally, but the second time, php-cgi crashed.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x0000000100418211 in _zend_mm_alloc_int (heap=0x101025a00, size=4) at /Users/hightman/Temp/setup/php-5.3.3/Zend/zend_alloc.c:1825
1825                            heap->cache[index] = best_fit->prev_free_block;
(gdb) bt
#0  0x0000000100418211 in _zend_mm_alloc_int (heap=0x101025a00, size=4) at /Users/hightman/Temp/setup/php-5.3.3/Zend/zend_alloc.c:1825
#1  0x00000001004196cc in _emalloc (size=4) at /Users/hightman/Temp/setup/php-5.3.3/Zend/zend_alloc.c:2340
#2  0x0000000100432af4 in init_op_array (op_array=0x100e5c2d0, type=2 '\002', initial_ops_size=64) at /Users/hightman/Temp/setup/php-5.3.3/Zend/zend_opcode.c:63
#3  0x00000001003fa309 in compile_file (file_handle=0x7fff5fbfd660, type=8) at zend_language_scanner.l:351
#4  0x000000010043f8ee in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /Users/hightman/Temp/setup/php-5.3.3/Zend/zend.c:1186
#5  0x00000001003c6e01 in php_execute_script (primary_file=0x7fff5fbfd660) at /Users/hightman/Temp/setup/php-5.3.3/main/main.c:2260
#6  0x00000001005222f3 in main (argc=3, argv=0x7fff5fbff850) at /Users/hightman/Temp/setup/php-5.3.3/sapi/cgi/cgi_main.c:2109

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-08 15:16 UTC] hightman at twomice dot net
I have resolved this bug after some hours hard work, but I don't know whether it is a good way and fully kill the bug.

1) Patch the source file 'zend/zend_language_scanner.l' as following diff output:

*** zend/zend_language_scanner.l.orig   2010-10-08 20:48:35.000000000 +0800
--- zend/zend_language_scanner.l        2010-10-08 20:49:36.000000000 +0800
***************
*** 355,360 ****
--- 355,361 ----
                zend_do_return(&retval_znode, 0 TSRMLS_CC);
                CG(in_compilation) = original_in_compilation;
                if (compiler_result==1) { /* parser error */
+                       zend_restore_lexical_state(&original_lex_state TSRMLS_CC);
                        zend_bailout();
                }
                compilation_successful=1;

2) Re-compile the php, and it will generate a new zend/zend_language_scanner.c automatically, but you should install `re2c` first. Otherwise, you should modify zend/zend_language_scanner.c refers to the above patch.
 [2011-07-10 14:12 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2011-07-10 14:12 UTC] felipe@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

I can't reproduce it.
 [2011-07-10 23:10 UTC] hightman at twomice dot net
I tested php-5.3.6 and php-5.3.3 respectively again.
The problem disappeared in 5.3.6, but still can reproduce in 5.3.3.

In the latest version seems to solve the problem, you can close this bug, but I still don't know the real reason of this bug.
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC