- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8k
Fix GH-13931: Applying zero offset to null pointer in Zend/zend_opcode.c #13938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
    
  
     Closed
                    Changes from 2 commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      fd6e7f9
              
                Fix GH-13931: Applying zero offset to null pointer in Zend/zend_opcode.c
              
              
                ndossche 0615e00
              
                Add tests
              
              
                ndossche 5a61065
              
                Move code to php_error_cb
              
              
                ndossche 9a85794
              
                Bailout already sets in_compilation=0
              
              
                ndossche e7e2160
              
                Only recover the compiler on compilation or parse error
              
              
                ndossche 438ffdb
              
                Fix indentation
              
              
                ndossche File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --TEST-- | ||
| GH-13931 (Applying zero offset to null pointer in Zend/zend_opcode.c) | ||
| --FILE-- | ||
| <?php | ||
|  | ||
| register_shutdown_function(function() { | ||
| var_dump(eval("return 1+3;")); | ||
| }); | ||
|  | ||
| eval(<<<EVAL | ||
| function foo () { | ||
| try { | ||
| break; | ||
| } finally { | ||
| } | ||
| } | ||
| foo(); | ||
| EVAL); | ||
|  | ||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: 'break' not in the 'loop' or 'switch' context in %s on line %d | ||
| int(4) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --TEST-- | ||
| Applying zero offset to null pointer in Zend/zend_opcode.c | ||
| --FILE-- | ||
| <?php | ||
| function foo () { | ||
| try { | ||
| break; | ||
| } finally { | ||
| } | ||
| } | ||
| foo(); | ||
| ?> | ||
| --PHPDBG-- | ||
| ev 1 + 3 | ||
| ev 2 ** 3 | ||
| q | ||
| --EXPECTF-- | ||
| Fatal error: 'break' not in the 'loop' or 'switch' context in %s on line %d | ||
| prompt> 4 | ||
| prompt> 8 | ||
| prompt> | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other calls to
shutdown_compilerare wrapped inzend_try, do we need that here? I don't believe so, looking at its implementation. But maybe you can double-check. 🙂There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really know why other locations surround it in a try, it doesn't seem necessary.
However, if wanted I can do this, it doesn't seem harmful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked again, and none of the frees in
shutdown_compilercan throw, because they are either just calls to efree, or free hash tables that contain strings or pointers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we call
shutdown_functionafter a fatal error on purpose. This is definitely not safe.We especially disable destructor calls in
php_error_cb().In any case, I think it's better to move this recovery code into
php_error_cb().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have moved the code to php_error_cb.
Good question, I don't know but I wouldn't be surprised people depend on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstogov Can you clarify why this would be problematic for shutdown functions? When compiling new files through includes in shutdown, the compile structures are cleaned and newly initialized. Nothing should be referencing the old values either, as the compilation has previously bailed. I might be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is right. People depends on every weird feature :(
This error handler may be called after ANY fatal error that stood something in inconsistent state. E.g. after memory overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't claim your recovery code. Recovery after parse errors should be possible.
I ask you to move this code to a more appropriate place (into
php_error_cb().or even higher).Also it may make sense to do this only for
E_PARSEerrors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error from the test case is an
E_COMPILE_ERRORinstead of aE_PARSE.I adjusted the code in php_error_cb to recover the compiler if either of these two happen.