php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71604 Aborted Generators continue after nested finally
Submitted: 2016-02-16 02:20 UTC Modified: -
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:-2 (-100.0%)
From: bwoebi@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.6Git-2016-02-16 (Git) OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bwoebi@php.net
New email:
PHP Version: OS:

 

 [2016-02-16 02:20 UTC] bwoebi@php.net
Description:
------------
L6  YIELD
L8  ECHO                    "INNER "
L8  FAST_RET<TO_CATCH>      ~0                   try-catch(0)
L10 CATCH                   "Exception"          $e                   1

and then it goes bad. When reaching the catch without an Exception, it goes to finally without fast_call u2.lineno variable being -1. [Or in master, where there's no target for the last catch, it immediately goes nuts.]

Could be easily fixed by just marking the other FAST_RET's fast_call u2.lineno variables as -1, but then there is the second case when an actual exception gets thrown while in finally and caught, where this approach does not work (as there is no further opcode after a successful catch).

Test script:
---------------
// First example

function gen() {
        try {
                try {
                        yield;
                } finally {
                        print "INNER\n";
                }
        } catch (Exception $e) {
                print "EX\n";
        } finally {
                print "OUTER\n";
        }
        print "NOTREACHED\n";
}
gen()->current();

// Second example

function gen2() {
        try {
                try {
                        yield;
                } finally {
                        print "INNER\n";
                        throw new Exception;
                }
        } catch (Exception $e) {
                print "EX\n";
        }
        print "NOTREACHED\n";
}
gen2()->current();

Expected result:
----------------
// First example:

INNER
OUTER

// Second example:

INNER
EX

Actual result:
--------------
// First example (undefined in master after OUTER step due to the last catch not having a target opline defined)

INNER
OUTER
NOTREACHED

// Second example

INNER
EX
NOTREACHED

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-28 12:40 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=921b3251b36eb5a930eb3de3496215833d3d548f
Log: Fix bug #71604
 [2016-05-28 12:40 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2016-07-20 11:30 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=921b3251b36eb5a930eb3de3496215833d3d548f
Log: Fix bug #71604
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 27 03:01:29 2024 UTC