php: throw and catch within a destructor causes exception on-the-fly to be lost
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
php |
Unknown
|
Unknown
|
|||
php5 (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
Lucid |
Won't Fix
|
Medium
|
Unassigned |
Bug Description
See the attached test case. The Outer::runInner() throws a test exception that is supposed to be catched in Outer::run(). However, before this the destructor of Inner will run as a result of stack unwinding while returning from Outer::runInner(). This, in turn, causes the original exception to be lost because Inner::tearDown() throws an exception which it later catches.
The test case is expected to output (tested official win32 builds 5.3.16 and 5.4.6):
$ php throw-test.php
Catched exception in Inner::tearDown(): test throw inside Inner::tearDown()
#0 /path/to/
#1 /path/to/
#2 /path/to/
#3 /path/to/
#4 {main}
OK: Catched exception in Outer::run(): test throw from Outer::runInner()
#0 /path/to/
#1 /path/to/
#2 {main}
The version distributed by ubuntu (PHP 5.3.2-1ubuntu4.17) outputs:
$ php throw-test.php
Catched exception in Inner::tearDown(): test throw inside Inner::tearDown()
#0 /home/mira/
#1 /home/mira/
#2 /home/mira/
#3 /home/mira/
#4 {main}
Notice the missing exception in Outer::run(). [Lines have been manually wrapped for this bug report.]
ProblemType: Bug
DistroRelease: Ubuntu 10.04
Package: php5-cli 5.3.2-1ubuntu4.17
ProcVersionSign
Uname: Linux 3.0.0-24-generic x86_64
Architecture: amd64
CheckboxSubmission: f0bf0101e3df07a
CheckboxSystem: b5acb6c9ca4017b
Date: Tue Aug 28 15:01:35 2012
InstallationMedia: Ubuntu 9.10 "Karmic Koala" - Release Candidate amd64 (20091020.3)
SourcePackage: php5
It just occurred to me that the test case written a bit differently could be program logic guarding authenticated session.
As a result, I'm marking this bug as "security" but keeping it still public because I'm not aware of real world PHP program suffering from a security issue because of this issue.