php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73337 try/catch not working with two exceptions inside a same operation
Submitted: 2016-10-18 10:27 UTC Modified: -
From: bwoebi@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.1.0RC3 OS: Irrelevant
Private report: No CVE-ID:
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: bwoebi@php.net
New email:
PHP Version: OS:

 

 [2016-10-18 10:27 UTC] bwoebi@php.net
Description:
------------
If two exceptions happen to be thrown inside a same opcode (the last one of both *must* be thrown from within a separate function, e.g. an userland destructor).

The bug is in zend_throw_exception_internal(). We do not overwrite EG(opline_before_exception) in case the current opcode is ZEND_HANDLE_EXCEPTION.
This is problematic in the case we aren't yet at that opcode, but it just got set to it by a previous call to zend_throw_exception_internal(). I.e. in case one exception has been triggered and then another exception is thrown within the same opcode.
This leads to throw_op_num (= EG(opline_before_exception) - EX(func)->op_array.opcodes) inside ZEND_HANDLE_EXCEPTION opcode being bogus and catching does not work thus.

Test script:
---------------
class d { function __destruct() { throw new Error; } }
try { new d + new d; } catch (Error $e) { print "Exception properly caught"; }

Expected result:
----------------
Exception properly caught

Actual result:
--------------
Fatal error: Uncaught Error in Command line code:1
Stack trace:
#0 Command line code(1): d->__destruct()
#1 {main}

Next Error in Command line code:1
Stack trace:
#0 Command line code(1): d->__destruct()
#1 {main}
  thrown in Command line code on line 1


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-18 12:10 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6558559bcc1cd24e3639e4a215e9d546ee05fc48
Log: Fixed bug #73337 (try/catch not working with two exceptions inside a same operation)
 [2016-10-18 12:10 UTC] dmitry@php.net
-Status: Open +Status: Closed
 [2016-10-18 12:11 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6558559bcc1cd24e3639e4a215e9d546ee05fc48
Log: Fixed bug #73337 (try/catch not working with two exceptions inside a same operation)
 [2016-10-25 15:21 UTC] krakjoe@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6558559bcc1cd24e3639e4a215e9d546ee05fc48
Log: Fixed bug #73337 (try/catch not working with two exceptions inside a same operation)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC