Skip to content

Commit 978b7de

Browse files
committed
Accept zend_object* in zend_get_exception_base
1 parent 7991fc2 commit 978b7de

File tree

4 files changed

+27
-32
lines changed

4 files changed

+27
-32
lines changed

Zend/zend_exceptions.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ static int zend_implement_throwable(zend_class_entry *interface, zend_class_entr
6464
}
6565
/* }}} */
6666

67-
static inline zend_class_entry *i_get_exception_base(zval *object) /* {{{ */
67+
static inline zend_class_entry *i_get_exception_base(zend_object *object) /* {{{ */
6868
{
69-
return instanceof_function(Z_OBJCE_P(object), zend_ce_exception) ? zend_ce_exception : zend_ce_error;
69+
return instanceof_function(object->ce, zend_ce_exception) ? zend_ce_exception : zend_ce_error;
7070
}
7171
/* }}} */
7272

73-
ZEND_API zend_class_entry *zend_get_exception_base(zval *object) /* {{{ */
73+
ZEND_API zend_class_entry *zend_get_exception_base(zend_object *object) /* {{{ */
7474
{
7575
return i_get_exception_base(object);
7676
}
@@ -99,15 +99,15 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo
9999
ZVAL_OBJ(&zv, exception);
100100
ex = &zv;
101101
do {
102-
ancestor = zend_read_property_ex(i_get_exception_base(&pv), Z_OBJ(pv), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
102+
ancestor = zend_read_property_ex(i_get_exception_base(add_previous), add_previous, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
103103
while (Z_TYPE_P(ancestor) == IS_OBJECT) {
104104
if (Z_OBJ_P(ancestor) == Z_OBJ_P(ex)) {
105105
OBJ_RELEASE(add_previous);
106106
return;
107107
}
108-
ancestor = zend_read_property_ex(i_get_exception_base(ancestor), Z_OBJ_P(ancestor), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
108+
ancestor = zend_read_property_ex(i_get_exception_base(Z_OBJ_P(ancestor)), Z_OBJ_P(ancestor), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
109109
}
110-
base_ce = i_get_exception_base(ex);
110+
base_ce = i_get_exception_base(Z_OBJ_P(ex));
111111
previous = zend_read_property_ex(base_ce, Z_OBJ_P(ex), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv);
112112
if (Z_TYPE_P(previous) == IS_NULL) {
113113
zend_update_property_ex(base_ce, ex, ZSTR_KNOWN(ZEND_STR_PREVIOUS), &pv);
@@ -235,7 +235,7 @@ static zend_object *zend_default_exception_new_ex(zend_class_entry *class_type,
235235
}
236236
Z_SET_REFCOUNT(trace, 0);
237237

238-
base_ce = i_get_exception_base(&obj);
238+
base_ce = i_get_exception_base(object);
239239

240240
if (EXPECTED((class_type != zend_ce_parse_error && class_type != zend_ce_compile_error)
241241
|| !(filename = zend_get_compiled_filename()))) {
@@ -285,7 +285,7 @@ ZEND_METHOD(Exception, __construct)
285285
zend_class_entry *base_ce;
286286

287287
object = ZEND_THIS;
288-
base_ce = i_get_exception_base(object);
288+
base_ce = i_get_exception_base(Z_OBJ_P(object));
289289

290290
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) {
291291
RETURN_THROWS();
@@ -309,9 +309,9 @@ ZEND_METHOD(Exception, __construct)
309309

310310
/* {{{ Exception unserialize checks */
311311
#define CHECK_EXC_TYPE(id, type) \
312-
pvalue = zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &value); \
312+
pvalue = zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &value); \
313313
if (Z_TYPE_P(pvalue) != IS_NULL && Z_TYPE_P(pvalue) != type) { \
314-
zend_unset_property(i_get_exception_base(object), object, ZSTR_VAL(ZSTR_KNOWN(id)), ZSTR_LEN(ZSTR_KNOWN(id))); \
314+
zend_unset_property(i_get_exception_base(Z_OBJ_P(object)), object, ZSTR_VAL(ZSTR_KNOWN(id)), ZSTR_LEN(ZSTR_KNOWN(id))); \
315315
}
316316

317317
ZEND_METHOD(Exception, __wakeup)
@@ -375,9 +375,9 @@ ZEND_METHOD(ErrorException, __construct)
375375
/* }}} */
376376

377377
#define GET_PROPERTY(object, id) \
378-
zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 0, &rv)
378+
zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 0, &rv)
379379
#define GET_PROPERTY_SILENT(object, id) \
380-
zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv)
380+
zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv)
381381

382382
/* {{{ Get the file in which the exception occurred */
383383
ZEND_METHOD(Exception, getFile)
@@ -601,7 +601,7 @@ ZEND_METHOD(Exception, getTraceAsString)
601601
ZEND_PARSE_PARAMETERS_NONE();
602602

603603
object = ZEND_THIS;
604-
base_ce = i_get_exception_base(object);
604+
base_ce = i_get_exception_base(Z_OBJ_P(object));
605605

606606
trace = zend_read_property_ex(base_ce, Z_OBJ_P(object), ZSTR_KNOWN(ZEND_STR_TRACE), 1, &rv);
607607
if (EG(exception)) {
@@ -711,7 +711,7 @@ ZEND_METHOD(Exception, __toString)
711711

712712
exception = ZEND_THIS;
713713
/* Reset apply counts */
714-
while (exception && Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(exception)) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
714+
while (exception && Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(Z_OBJ_P(exception))) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
715715
if (Z_IS_RECURSIVE_P(exception)) {
716716
Z_UNPROTECT_RECURSION_P(exception);
717717
} else {
@@ -721,7 +721,7 @@ ZEND_METHOD(Exception, __toString)
721721
}
722722

723723
exception = ZEND_THIS;
724-
base_ce = i_get_exception_base(exception);
724+
base_ce = i_get_exception_base(Z_OBJ_P(exception));
725725

726726
/* We store the result in the private property string so we can access
727727
* the result in uncaught exception handlers without memleaks. */
@@ -940,7 +940,7 @@ ZEND_API ZEND_COLD int zend_exception_error(zend_object *ex, int severity) /* {{
940940
if (Z_TYPE(tmp) != IS_STRING) {
941941
zend_error(E_WARNING, "%s::__toString() must return a string", ZSTR_VAL(ce_exception->name));
942942
} else {
943-
zend_update_property_ex(i_get_exception_base(&exception), &exception, ZSTR_KNOWN(ZEND_STR_STRING), &tmp);
943+
zend_update_property_ex(i_get_exception_base(ex), &exception, ZSTR_KNOWN(ZEND_STR_STRING), &tmp);
944944
}
945945
}
946946
zval_ptr_dtor(&tmp);

Zend/zend_exceptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ZEND_API ZEND_COLD void zend_throw_exception_internal(zend_object *exception);
4545

4646
void zend_register_default_exception(void);
4747

48-
ZEND_API zend_class_entry *zend_get_exception_base(zval *object);
48+
ZEND_API zend_class_entry *zend_get_exception_base(zend_object *object);
4949

5050
/* Deprecated - Use zend_ce_exception directly instead */
5151
ZEND_API zend_class_entry *zend_exception_get_default(void);

ext/sodium/libsodium.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,8 @@ ZEND_GET_MODULE(sodium)
9696

9797
/* Remove argument information from backtrace to prevent information leaks */
9898
static void sodium_remove_param_values_from_backtrace(zend_object *obj) {
99-
zval obj_zv, rv, *trace;
100-
101-
ZVAL_OBJ(&obj_zv, obj);
102-
trace = zend_read_property(zend_get_exception_base(&obj_zv), Z_OBJ(obj_zv), "trace", sizeof("trace")-1, 0, &rv);
99+
zval rv;
100+
zval *trace = zend_read_property(zend_get_exception_base(obj), obj, "trace", sizeof("trace")-1, 0, &rv);
103101
if (trace && Z_TYPE_P(trace) == IS_ARRAY) {
104102
zval *frame;
105103
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(trace), frame) {

sapi/phpdbg/phpdbg_prompt.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -726,16 +726,16 @@ static inline void phpdbg_handle_exception(void) /* {{{ */
726726

727727
ZVAL_OBJ(&zv, ex);
728728
zend_call_known_instance_method_with_0_params(ex->ce->__tostring, ex, &tmp);
729-
file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("file"), 1, &rv));
730-
line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("line"), 1, &rv));
729+
file = zval_get_string(zend_read_property(zend_get_exception_base(ex), ex, ZEND_STRL("file"), 1, &rv));
730+
line = zval_get_long(zend_read_property(zend_get_exception_base(ex), ex, ZEND_STRL("line"), 1, &rv));
731731

732732
if (EG(exception)) {
733733
EG(exception) = NULL;
734734
msg = ZSTR_EMPTY_ALLOC();
735735
} else {
736-
zend_update_property_string(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), Z_STRVAL(tmp));
736+
zend_update_property_string(zend_get_exception_base(ex), &zv, ZEND_STRL("string"), Z_STRVAL(tmp));
737737
zval_ptr_dtor(&tmp);
738-
msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("string"), 1, &rv));
738+
msg = zval_get_string(zend_read_property(zend_get_exception_base(ex), ex, ZEND_STRL("string"), 1, &rv));
739739
}
740740

741741
phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT, ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line);
@@ -1721,9 +1721,6 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
17211721
/* check for uncaught exceptions */
17221722
if (exception && PHPDBG_G(handled_exception) != exception && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
17231723
zend_execute_data *prev_ex = execute_data;
1724-
zval zv, rv;
1725-
zend_string *file, *msg;
1726-
zend_long line;
17271724

17281725
do {
17291726
prev_ex = zend_generator_check_placeholder_frame(prev_ex);
@@ -1739,10 +1736,10 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
17391736

17401737
PHPDBG_G(handled_exception) = exception;
17411738

1742-
ZVAL_OBJ(&zv, exception);
1743-
file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("file"), 1, &rv));
1744-
line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("line"), 1, &rv));
1745-
msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("message"), 1, &rv));
1739+
zval rv;
1740+
zend_string *file = zval_get_string(zend_read_property(zend_get_exception_base(exception), exception, ZEND_STRL("file"), 1, &rv));
1741+
zend_long line = zval_get_long(zend_read_property(zend_get_exception_base(exception), exception, ZEND_STRL("line"), 1, &rv));
1742+
zend_string *msg = zval_get_string(zend_read_property(zend_get_exception_base(exception), exception, ZEND_STRL("message"), 1, &rv));
17461743

17471744
phpdbg_error("exception",
17481745
"name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"",

0 commit comments

Comments
 (0)