diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-08-07 15:15:50 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-08-07 16:40:27 +0200 |
commit | 978b7de244197ae7b7a7c2a5d7e1dd790254455f (patch) | |
tree | 27a3ab1ddea0f19bca9df07b10dff24071601b19 | |
parent | 7991fc2753c9c15eeccb2a6384050a21c6ffaa71 (diff) | |
download | php-git-978b7de244197ae7b7a7c2a5d7e1dd790254455f.tar.gz |
Accept zend_object* in zend_get_exception_base
-rw-r--r-- | Zend/zend_exceptions.c | 32 | ||||
-rw-r--r-- | Zend/zend_exceptions.h | 2 | ||||
-rw-r--r-- | ext/sodium/libsodium.c | 6 | ||||
-rw-r--r-- | sapi/phpdbg/phpdbg_prompt.c | 19 |
4 files changed, 27 insertions, 32 deletions
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index aa0c8e64a4..c2cd1bdb8d 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -64,13 +64,13 @@ static int zend_implement_throwable(zend_class_entry *interface, zend_class_entr } /* }}} */ -static inline zend_class_entry *i_get_exception_base(zval *object) /* {{{ */ +static inline zend_class_entry *i_get_exception_base(zend_object *object) /* {{{ */ { - return instanceof_function(Z_OBJCE_P(object), zend_ce_exception) ? zend_ce_exception : zend_ce_error; + return instanceof_function(object->ce, zend_ce_exception) ? zend_ce_exception : zend_ce_error; } /* }}} */ -ZEND_API zend_class_entry *zend_get_exception_base(zval *object) /* {{{ */ +ZEND_API zend_class_entry *zend_get_exception_base(zend_object *object) /* {{{ */ { return i_get_exception_base(object); } @@ -99,15 +99,15 @@ void zend_exception_set_previous(zend_object *exception, zend_object *add_previo ZVAL_OBJ(&zv, exception); ex = &zv; do { - ancestor = zend_read_property_ex(i_get_exception_base(&pv), Z_OBJ(pv), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); + ancestor = zend_read_property_ex(i_get_exception_base(add_previous), add_previous, ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); while (Z_TYPE_P(ancestor) == IS_OBJECT) { if (Z_OBJ_P(ancestor) == Z_OBJ_P(ex)) { OBJ_RELEASE(add_previous); return; } - ancestor = zend_read_property_ex(i_get_exception_base(ancestor), Z_OBJ_P(ancestor), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); + ancestor = zend_read_property_ex(i_get_exception_base(Z_OBJ_P(ancestor)), Z_OBJ_P(ancestor), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); } - base_ce = i_get_exception_base(ex); + base_ce = i_get_exception_base(Z_OBJ_P(ex)); previous = zend_read_property_ex(base_ce, Z_OBJ_P(ex), ZSTR_KNOWN(ZEND_STR_PREVIOUS), 1, &rv); if (Z_TYPE_P(previous) == IS_NULL) { 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, } Z_SET_REFCOUNT(trace, 0); - base_ce = i_get_exception_base(&obj); + base_ce = i_get_exception_base(object); if (EXPECTED((class_type != zend_ce_parse_error && class_type != zend_ce_compile_error) || !(filename = zend_get_compiled_filename()))) { @@ -285,7 +285,7 @@ ZEND_METHOD(Exception, __construct) zend_class_entry *base_ce; object = ZEND_THIS; - base_ce = i_get_exception_base(object); + base_ce = i_get_exception_base(Z_OBJ_P(object)); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|SlO!", &message, &code, &previous, zend_ce_throwable) == FAILURE) { RETURN_THROWS(); @@ -309,9 +309,9 @@ ZEND_METHOD(Exception, __construct) /* {{{ Exception unserialize checks */ #define CHECK_EXC_TYPE(id, type) \ - pvalue = zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &value); \ + pvalue = zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &value); \ if (Z_TYPE_P(pvalue) != IS_NULL && Z_TYPE_P(pvalue) != type) { \ - zend_unset_property(i_get_exception_base(object), object, ZSTR_VAL(ZSTR_KNOWN(id)), ZSTR_LEN(ZSTR_KNOWN(id))); \ + zend_unset_property(i_get_exception_base(Z_OBJ_P(object)), object, ZSTR_VAL(ZSTR_KNOWN(id)), ZSTR_LEN(ZSTR_KNOWN(id))); \ } ZEND_METHOD(Exception, __wakeup) @@ -375,9 +375,9 @@ ZEND_METHOD(ErrorException, __construct) /* }}} */ #define GET_PROPERTY(object, id) \ - zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 0, &rv) + zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 0, &rv) #define GET_PROPERTY_SILENT(object, id) \ - zend_read_property_ex(i_get_exception_base(object), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv) + zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv) /* {{{ Get the file in which the exception occurred */ ZEND_METHOD(Exception, getFile) @@ -601,7 +601,7 @@ ZEND_METHOD(Exception, getTraceAsString) ZEND_PARSE_PARAMETERS_NONE(); object = ZEND_THIS; - base_ce = i_get_exception_base(object); + base_ce = i_get_exception_base(Z_OBJ_P(object)); trace = zend_read_property_ex(base_ce, Z_OBJ_P(object), ZSTR_KNOWN(ZEND_STR_TRACE), 1, &rv); if (EG(exception)) { @@ -711,7 +711,7 @@ ZEND_METHOD(Exception, __toString) exception = ZEND_THIS; /* Reset apply counts */ - while (exception && Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(exception)) && instanceof_function(Z_OBJCE_P(exception), base_ce)) { + 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)) { if (Z_IS_RECURSIVE_P(exception)) { Z_UNPROTECT_RECURSION_P(exception); } else { @@ -721,7 +721,7 @@ ZEND_METHOD(Exception, __toString) } exception = ZEND_THIS; - base_ce = i_get_exception_base(exception); + base_ce = i_get_exception_base(Z_OBJ_P(exception)); /* We store the result in the private property string so we can access * 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) /* {{ if (Z_TYPE(tmp) != IS_STRING) { zend_error(E_WARNING, "%s::__toString() must return a string", ZSTR_VAL(ce_exception->name)); } else { - zend_update_property_ex(i_get_exception_base(&exception), &exception, ZSTR_KNOWN(ZEND_STR_STRING), &tmp); + zend_update_property_ex(i_get_exception_base(ex), &exception, ZSTR_KNOWN(ZEND_STR_STRING), &tmp); } } zval_ptr_dtor(&tmp); diff --git a/Zend/zend_exceptions.h b/Zend/zend_exceptions.h index adc58df13b..7e8c73b1e9 100644 --- a/Zend/zend_exceptions.h +++ b/Zend/zend_exceptions.h @@ -45,7 +45,7 @@ ZEND_API ZEND_COLD void zend_throw_exception_internal(zend_object *exception); void zend_register_default_exception(void); -ZEND_API zend_class_entry *zend_get_exception_base(zval *object); +ZEND_API zend_class_entry *zend_get_exception_base(zend_object *object); /* Deprecated - Use zend_ce_exception directly instead */ ZEND_API zend_class_entry *zend_exception_get_default(void); diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index ecb11d5f38..7a1751b394 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -96,10 +96,8 @@ ZEND_GET_MODULE(sodium) /* Remove argument information from backtrace to prevent information leaks */ static void sodium_remove_param_values_from_backtrace(zend_object *obj) { - zval obj_zv, rv, *trace; - - ZVAL_OBJ(&obj_zv, obj); - trace = zend_read_property(zend_get_exception_base(&obj_zv), Z_OBJ(obj_zv), "trace", sizeof("trace")-1, 0, &rv); + zval rv; + zval *trace = zend_read_property(zend_get_exception_base(obj), obj, "trace", sizeof("trace")-1, 0, &rv); if (trace && Z_TYPE_P(trace) == IS_ARRAY) { zval *frame; ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(trace), frame) { diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 7647859222..3d44d10af0 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -726,16 +726,16 @@ static inline void phpdbg_handle_exception(void) /* {{{ */ ZVAL_OBJ(&zv, ex); zend_call_known_instance_method_with_0_params(ex->ce->__tostring, ex, &tmp); - file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("file"), 1, &rv)); - line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("line"), 1, &rv)); + file = zval_get_string(zend_read_property(zend_get_exception_base(ex), ex, ZEND_STRL("file"), 1, &rv)); + line = zval_get_long(zend_read_property(zend_get_exception_base(ex), ex, ZEND_STRL("line"), 1, &rv)); if (EG(exception)) { EG(exception) = NULL; msg = ZSTR_EMPTY_ALLOC(); } else { - zend_update_property_string(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), Z_STRVAL(tmp)); + zend_update_property_string(zend_get_exception_base(ex), &zv, ZEND_STRL("string"), Z_STRVAL(tmp)); zval_ptr_dtor(&tmp); - msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("string"), 1, &rv)); + msg = zval_get_string(zend_read_property(zend_get_exception_base(ex), ex, ZEND_STRL("string"), 1, &rv)); } 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) /* {{{ */ /* check for uncaught exceptions */ if (exception && PHPDBG_G(handled_exception) != exception && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { zend_execute_data *prev_ex = execute_data; - zval zv, rv; - zend_string *file, *msg; - zend_long line; do { prev_ex = zend_generator_check_placeholder_frame(prev_ex); @@ -1739,10 +1736,10 @@ void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */ PHPDBG_G(handled_exception) = exception; - ZVAL_OBJ(&zv, exception); - file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("file"), 1, &rv)); - line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("line"), 1, &rv)); - msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), Z_OBJ(zv), ZEND_STRL("message"), 1, &rv)); + zval rv; + zend_string *file = zval_get_string(zend_read_property(zend_get_exception_base(exception), exception, ZEND_STRL("file"), 1, &rv)); + zend_long line = zval_get_long(zend_read_property(zend_get_exception_base(exception), exception, ZEND_STRL("line"), 1, &rv)); + zend_string *msg = zval_get_string(zend_read_property(zend_get_exception_base(exception), exception, ZEND_STRL("message"), 1, &rv)); phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", |