Skip to content

Commit c2f7fad

Browse files
laruenceweltling
authored andcommitted
Port the fix of 5.6 to 7.0
1 parent 7d2a26b commit c2f7fad

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

Zend/tests/bug70944.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ try {
2525
}
2626
?>
2727
--EXPECTF--
28-
string(%d) "exception 'Exception' with message 'Foo' in %sbug70944.php:%d
28+
string(%d) "Exception: Foo in %sbug70944.php:%d
2929
Stack trace:
3030
#0 {main}"
31-
string(%d) "exception 'Exception' with message 'Foo' in %sbug70944.php:%d
31+
string(%d) "Exception: Foo in %sbug70944.php:%d
3232
Stack trace:
3333
#0 {main}
3434

35-
Next exception 'Exception' with message 'Dummy' in %sbug70944.php:%d
35+
Next Exception: Dummy in %sbug70944.php:%d
3636
Stack trace:
3737
#0 {main}"

Zend/zend_exceptions.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,38 @@ ZEND_API zend_class_entry *zend_get_exception_base(zval *object)
7070

7171
void zend_exception_set_previous(zend_object *exception, zend_object *add_previous)
7272
{
73-
zval *previous, *pzv;
74-
zval tmp, zv, rv;
73+
zval *previous, *ancestor, *ex;
74+
zval pv, zv, rv;
7575
zend_class_entry *base_ce;
7676

7777
if (exception == add_previous || !add_previous || !exception) {
7878
return;
7979
}
80-
ZVAL_OBJ(&tmp, add_previous);
81-
if (!instanceof_function(Z_OBJCE(tmp), zend_ce_throwable)) {
80+
ZVAL_OBJ(&pv, add_previous);
81+
if (!instanceof_function(Z_OBJCE(pv), zend_ce_throwable)) {
8282
zend_error_noreturn(E_CORE_ERROR, "Previous exception must implement Throwable");
8383
return;
8484
}
85-
pzv = zend_read_property(i_get_exception_base(&tmp), &tmp, "previous", sizeof("previous")-1, 1, &rv);
86-
while (Z_TYPE_P(pzv) == IS_OBJECT) {
87-
if (Z_OBJ_P(pzv) == exception) {
88-
return;
89-
}
90-
pzv = zend_read_property(i_get_exception_base(pzv), pzv, "previous", sizeof("previous")-1, 1, &rv);
91-
}
9285
ZVAL_OBJ(&zv, exception);
93-
pzv = &zv;
86+
ex = &zv;
9487
do {
95-
base_ce = i_get_exception_base(pzv);
96-
previous = zend_read_property(base_ce, pzv, "previous", sizeof("previous")-1, 1, &rv);
88+
ancestor = zend_read_property(i_get_exception_base(&pv), &pv, "previous", sizeof("previous")-1, 1, &rv);
89+
while (Z_TYPE_P(ancestor) == IS_OBJECT) {
90+
if (Z_OBJ_P(ancestor) == Z_OBJ_P(ex)) {
91+
OBJ_RELEASE(add_previous);
92+
return;
93+
}
94+
ancestor = zend_read_property(i_get_exception_base(ancestor), ancestor, "previous", sizeof("previous")-1, 1, &rv);
95+
}
96+
base_ce = i_get_exception_base(ex);
97+
previous = zend_read_property(base_ce, ex, "previous", sizeof("previous")-1, 1, &rv);
9798
if (Z_TYPE_P(previous) == IS_NULL) {
98-
zend_update_property(base_ce, pzv, "previous", sizeof("previous")-1, &tmp);
99+
zend_update_property(base_ce, ex, "previous", sizeof("previous")-1, &pv);
99100
GC_REFCOUNT(add_previous)--;
100101
return;
101102
}
102-
pzv = previous;
103-
} while (pzv && Z_OBJ_P(pzv) != add_previous);
103+
ex = previous;
104+
} while (Z_OBJ_P(ex) != add_previous);
104105
}
105106

106107
void zend_exception_save(void) /* {{{ */

0 commit comments

Comments
 (0)