From: Máté Kocsis Date: Wed, 1 Jan 2020 15:42:30 +0000 (+0100) Subject: Use RETURN_THROWS() after zend_throw_error() X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=349a28646163b0e1433fad450edbac8215fc5b32;p=php Use RETURN_THROWS() after zend_throw_error() --- diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 19ec415c73..a7a1f41f59 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -289,7 +289,7 @@ ZEND_METHOD(exception, __construct) ce = base_ce; } zend_throw_error(NULL, "Wrong parameters for %s([string $message [, long $code [, Throwable $previous = NULL]]])", ZSTR_VAL(ce->name)); - return; + RETURN_THROWS(); } if (message) { @@ -355,7 +355,7 @@ ZEND_METHOD(error_exception, __construct) ce = zend_ce_error_exception; } zend_throw_error(NULL, "Wrong parameters for %s([string $message [, long $code, [ long $severity, [ string $filename, [ long $lineno [, Throwable $previous = NULL]]]]]])", ZSTR_VAL(ce->name)); - return; + RETURN_THROWS(); } object = ZEND_THIS; diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 1c3c11fc35..13fd7e005e 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -302,7 +302,7 @@ static zend_object_handlers date_object_handlers_period; #define DATE_CHECK_INITIALIZED(member, class_name) \ if (!(member)) { \ zend_throw_error(NULL, "The " #class_name " object has not been correctly initialized by its constructor"); \ - return; \ + RETURN_THROWS(); \ } static void date_object_free_storage_date(zend_object *object); diff --git a/ext/dom/document.c b/ext/dom/document.c index 07eaec58f8..473593e8a7 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -1730,7 +1730,7 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type if (!vptr) { xmlSchemaFree(sptr); zend_throw_error(NULL, "Invalid Schema Validation Context"); - RETURN_FALSE; + RETURN_THROWS(); } if (flags & XML_SCHEMA_VAL_VC_I_CREATE) { @@ -1829,7 +1829,7 @@ static void _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int typ if (!vptr) { xmlRelaxNGFree(sptr); zend_throw_error(NULL, "Invalid RelaxNG Validation Context"); - RETURN_FALSE; + RETURN_THROWS(); } xmlRelaxNGSetValidErrors(vptr, php_libxml_error_handler, php_libxml_error_handler, vptr); diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 6a6292105b..25dd1d95d4 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -2819,7 +2819,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */ handle = DL_LOAD(ZSTR_VAL(lib)); if (!handle) { zend_throw_error(zend_ffi_exception_ce, "Failed loading '%s'", ZSTR_VAL(lib)); - return; + RETURN_THROWS(); } #ifdef RTLD_DEFAULT } else if (1) { @@ -3345,7 +3345,7 @@ ZEND_METHOD(FFI, load) /* {{{ */ if (CG(compiler_options) & ZEND_COMPILE_PRELOAD_IN_CHILD) { zend_throw_error(zend_ffi_exception_ce, "FFI::load() doesn't work in conjunction with \"opcache.preload_user\". Use \"ffi.preload\" instead."); - return; + RETURN_THROWS(); } ffi = zend_ffi_load(ZSTR_VAL(fn), (CG(compiler_options) & ZEND_COMPILE_PRELOAD) != 0); @@ -3373,7 +3373,7 @@ ZEND_METHOD(FFI, scope) /* {{{ */ if (!scope) { zend_throw_error(zend_ffi_exception_ce, "Failed loading scope '%s'", ZSTR_VAL(scope_name)); - return; + RETURN_THROWS(); } ffi = (zend_ffi*)zend_ffi_new(zend_ffi_ce); @@ -3687,7 +3687,7 @@ ZEND_METHOD(FFI, free) /* {{{ */ if (ZEND_FFI_TYPE(cdata->type)->kind == ZEND_FFI_TYPE_POINTER) { if (!cdata->ptr) { zend_throw_error(zend_ffi_exception_ce, "NULL pointer dereference"); - return; + RETURN_THROWS(); } if (cdata->ptr != (void*)&cdata->ptr_holder) { pefree(*(void**)cdata->ptr, cdata->flags & ZEND_FFI_FLAG_PERSISTENT); @@ -3857,7 +3857,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */ } else if (type->size > old_type->size) { zend_object_release(&cdata->std); zend_throw_error(zend_ffi_exception_ce, "attempt to cast to larger type"); - return; + RETURN_THROWS(); } else if (ptr != &old_cdata->ptr_holder) { cdata->ptr = ptr; } else { @@ -4001,16 +4001,16 @@ ZEND_METHOD(FFI, arrayType) /* {{{ */ if (type->kind == ZEND_FFI_TYPE_FUNC) { zend_throw_error(zend_ffi_exception_ce, "array of functions is not allowed"); - return; + RETURN_THROWS(); } else if (type->kind == ZEND_FFI_TYPE_ARRAY && (type->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY)) { zend_throw_error(zend_ffi_exception_ce, "only the leftmost array can be undimensioned"); - return; + RETURN_THROWS(); } else if (type->kind == ZEND_FFI_TYPE_VOID) { zend_throw_error(zend_ffi_exception_ce, "array of 'void' is not allowed"); - return; + RETURN_THROWS(); } else if (type->attr & ZEND_FFI_ATTR_INCOMPLETE_TAG) { zend_throw_error(zend_ffi_exception_ce, "array of incomplete type is not allowed"); - return; + RETURN_THROWS(); } if (ZEND_FFI_TYPE_IS_OWNED(ctype->type)) { @@ -4032,11 +4032,11 @@ ZEND_METHOD(FFI, arrayType) /* {{{ */ if (n < 0) { zend_throw_error(zend_ffi_exception_ce, "negative array index"); zend_ffi_type_dtor(type); - return; + RETURN_THROWS(); } else if (ZEND_FFI_TYPE(type)->kind == ZEND_FFI_TYPE_ARRAY && (ZEND_FFI_TYPE(type)->attr & ZEND_FFI_ATTR_INCOMPLETE_ARRAY)) { zend_throw_error(zend_ffi_exception_ce, "only the leftmost array can be undimensioned"); zend_ffi_type_dtor(type); - return; + RETURN_THROWS(); } new_type = emalloc(sizeof(zend_ffi_type)); @@ -4187,7 +4187,7 @@ ZEND_METHOD(FFI, memcpy) /* {{{ */ ptr1 = cdata1->ptr; if (type1->kind != ZEND_FFI_TYPE_POINTER && size > type1->size) { zend_throw_error(zend_ffi_exception_ce, "attempt to write over data boundary"); - return; + RETURN_THROWS(); } } @@ -4196,7 +4196,7 @@ ZEND_METHOD(FFI, memcpy) /* {{{ */ ptr2 = Z_STRVAL_P(zv2); if (size > Z_STRLEN_P(zv2)) { zend_throw_error(zend_ffi_exception_ce, "attempt to read over string boundary"); - return; + RETURN_THROWS(); } } else if (Z_TYPE_P(zv2) == IS_OBJECT && Z_OBJCE_P(zv2) == zend_ffi_cdata_ce) { cdata2 = (zend_ffi_cdata*)Z_OBJ_P(zv2); @@ -4207,7 +4207,7 @@ ZEND_METHOD(FFI, memcpy) /* {{{ */ ptr2 = cdata2->ptr; if (type2->kind != ZEND_FFI_TYPE_POINTER && size > type2->size) { zend_throw_error(zend_ffi_exception_ce, "attempt to read over data boundary"); - return; + RETURN_THROWS(); } } } else { @@ -4240,7 +4240,7 @@ ZEND_METHOD(FFI, memcmp) /* {{{ */ ptr1 = Z_STRVAL_P(zv1); if (size > Z_STRLEN_P(zv1)) { zend_throw_error(zend_ffi_exception_ce, "attempt to read over string boundary"); - return; + RETURN_THROWS(); } } else if (Z_TYPE_P(zv1) == IS_OBJECT && Z_OBJCE_P(zv1) == zend_ffi_cdata_ce) { cdata1 = (zend_ffi_cdata*)Z_OBJ_P(zv1); @@ -4251,7 +4251,7 @@ ZEND_METHOD(FFI, memcmp) /* {{{ */ ptr1 = cdata1->ptr; if (type1->kind != ZEND_FFI_TYPE_POINTER && size > type1->size) { zend_throw_error(zend_ffi_exception_ce, "attempt to read over data boundary"); - return; + RETURN_THROWS(); } } } else { @@ -4264,7 +4264,7 @@ ZEND_METHOD(FFI, memcmp) /* {{{ */ ptr2 = Z_STRVAL_P(zv2); if (size > Z_STRLEN_P(zv2)) { zend_throw_error(zend_ffi_exception_ce, "attempt to read over string boundary"); - return; + RETURN_THROWS(); } } else if (Z_TYPE_P(zv2) == IS_OBJECT && Z_OBJCE_P(zv2) == zend_ffi_cdata_ce) { cdata2 = (zend_ffi_cdata*)Z_OBJ_P(zv2); @@ -4275,7 +4275,7 @@ ZEND_METHOD(FFI, memcmp) /* {{{ */ ptr2 = cdata2->ptr; if (type2->kind != ZEND_FFI_TYPE_POINTER && size > type2->size) { zend_throw_error(zend_ffi_exception_ce, "attempt to read over data boundary"); - return; + RETURN_THROWS(); } } } else { @@ -4317,7 +4317,7 @@ ZEND_METHOD(FFI, memset) /* {{{ */ ptr = cdata->ptr; if (type->kind != ZEND_FFI_TYPE_POINTER && size > type->size) { zend_throw_error(zend_ffi_exception_ce, "attempt to write over data boundary"); - return; + RETURN_THROWS(); } } @@ -4349,7 +4349,7 @@ ZEND_METHOD(FFI, string) /* {{{ */ ptr = cdata->ptr; if (type->kind != ZEND_FFI_TYPE_POINTER && size > type->size) { zend_throw_error(zend_ffi_exception_ce, "attempt to read over data boundary"); - return; + RETURN_THROWS(); } } RETURN_STRINGL((char*)ptr, size); @@ -4360,7 +4360,7 @@ ZEND_METHOD(FFI, string) /* {{{ */ ptr = cdata->ptr; } else { zend_throw_error(zend_ffi_exception_ce, "FFI\\Cdata is not a C string"); - return; + RETURN_THROWS(); } RETURN_STRING((char*)ptr); } @@ -4389,7 +4389,7 @@ ZEND_METHOD(FFI, isNull) /* {{{ */ if (type->kind != ZEND_FFI_TYPE_POINTER){ zend_throw_error(zend_ffi_exception_ce, "FFI\\Cdata is not a pointer"); - return; + RETURN_THROWS(); } RETURN_BOOL(*(void**)cdata->ptr == NULL); diff --git a/ext/hash/hash.c b/ext/hash/hash.c index 60ab85379e..b79894a33b 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -253,17 +253,17 @@ static void php_hash_do_hash_hmac(INTERNAL_FUNCTION_PARAMETERS, int isfilename, ops = php_hash_fetch_ops(algo, algo_len); if (!ops) { zend_throw_error(NULL, "Unknown hashing algorithm: %s", algo); - return; + RETURN_THROWS(); } else if (!ops->is_crypto) { zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", algo); - return; + RETURN_THROWS(); } if (isfilename) { if (CHECK_NULL_PATH(data, data_len)) { zend_throw_error(NULL, "Invalid path"); - return; + RETURN_THROWS(); } stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); if (!stream) { @@ -359,18 +359,18 @@ PHP_FUNCTION(hash_init) ops = php_hash_fetch_ops(ZSTR_VAL(algo), ZSTR_LEN(algo)); if (!ops) { zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); - return; + RETURN_THROWS(); } if (options & PHP_HASH_HMAC) { if (!ops->is_crypto) { zend_throw_error(NULL, "HMAC requested with a non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo)); - return; + RETURN_THROWS(); } if (!key || (ZSTR_LEN(key) == 0)) { /* Note: a zero length key is no key at all */ zend_throw_error(NULL, "HMAC requested without a key"); - return; + RETURN_THROWS(); } } @@ -415,7 +415,7 @@ PHP_FUNCTION(hash_init) #define PHP_HASHCONTEXT_VERIFY(func, hash) { \ if (!hash->context) { \ zend_throw_error(NULL, "%s(): supplied resource is not a valid Hash Context resource", func); \ - return; \ + RETURN_THROWS(); \ } \ } @@ -587,7 +587,7 @@ PHP_FUNCTION(hash_copy) zval_ptr_dtor(return_value); zend_throw_error(NULL, "Cannot copy hash"); - return; + RETURN_THROWS(); } } /* }}} */ @@ -648,27 +648,27 @@ PHP_FUNCTION(hash_hkdf) ops = php_hash_fetch_ops(ZSTR_VAL(algo), ZSTR_LEN(algo)); if (!ops) { zend_throw_error(NULL, "Unknown hashing algorithm: %s", ZSTR_VAL(algo)); - return; + RETURN_THROWS(); } if (!ops->is_crypto) { zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", ZSTR_VAL(algo)); - return; + RETURN_THROWS(); } if (ZSTR_LEN(ikm) == 0) { zend_throw_error(NULL, "Input keying material cannot be empty"); - return; + RETURN_THROWS(); } if (length < 0) { zend_throw_error(NULL, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length); - return; + RETURN_THROWS(); } else if (length == 0) { length = ops->digest_size; } else if (length > (zend_long) (ops->digest_size * 255)) { zend_throw_error(NULL, "Length must be less than or equal to %zd: " ZEND_LONG_FMT, ops->digest_size * 255, length); - return; + RETURN_THROWS(); } context = emalloc(ops->context_size); @@ -748,26 +748,26 @@ PHP_FUNCTION(hash_pbkdf2) ops = php_hash_fetch_ops(algo, algo_len); if (!ops) { zend_throw_error(NULL, "Unknown hashing algorithm: %s", algo); - return; + RETURN_THROWS(); } else if (!ops->is_crypto) { zend_throw_error(NULL, "Non-cryptographic hashing algorithm: %s", algo); - return; + RETURN_THROWS(); } if (iterations <= 0) { zend_throw_error(NULL, "Iterations must be a positive integer: " ZEND_LONG_FMT, iterations); - return; + RETURN_THROWS(); } if (length < 0) { zend_throw_error(NULL, "Length must be greater than or equal to 0: " ZEND_LONG_FMT, length); - return; + RETURN_THROWS(); } if (salt_len > INT_MAX - 4) { zend_throw_error(NULL, "Supplied salt is too long, max of INT_MAX - 4 bytes: %zd supplied", salt_len); - return; + RETURN_THROWS(); } context = emalloc(ops->context_size); diff --git a/ext/intl/collator/collator_compare.c b/ext/intl/collator/collator_compare.c index 4b6ad1fb92..17d5aff12e 100644 --- a/ext/intl/collator/collator_compare.c +++ b/ext/intl/collator/collator_compare.c @@ -59,7 +59,7 @@ PHP_FUNCTION( collator_compare ) "Object not initialized", 0 ); zend_throw_error(NULL, "Object not initialized"); - RETURN_FALSE; + RETURN_THROWS(); } /* diff --git a/ext/intl/collator/collator_locale.c b/ext/intl/collator/collator_locale.c index f669fb4717..66390c2d32 100644 --- a/ext/intl/collator/collator_locale.c +++ b/ext/intl/collator/collator_locale.c @@ -52,7 +52,7 @@ PHP_FUNCTION( collator_get_locale ) "Object not initialized", 0 ); zend_throw_error(NULL, "Object not initialized"); - RETURN_FALSE; + RETURN_THROWS(); } /* Get locale by specified type. */ diff --git a/ext/intl/collator/collator_sort.c b/ext/intl/collator/collator_sort.c index 0ed58790e4..bd235d804d 100644 --- a/ext/intl/collator/collator_sort.c +++ b/ext/intl/collator/collator_sort.c @@ -404,7 +404,7 @@ PHP_FUNCTION( collator_sort_with_sort_keys ) "Object not initialized", 0 ); zend_throw_error(NULL, "Object not initialized"); - RETURN_FALSE; + RETURN_THROWS(); } /* @@ -567,7 +567,7 @@ PHP_FUNCTION( collator_get_sort_key ) "Object not initialized", 0 ); zend_throw_error(NULL, "Object not initialized"); - RETURN_FALSE; + RETURN_THROWS(); } /* diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index 4bb8ee76c1..a4baa58dcb 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -1209,19 +1209,19 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags } if (UNEXPECTED(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_TRAIT|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) { zend_throw_error(NULL, "Class '%s' cannot be instantiated", ZSTR_VAL(ce->name)); - return; + RETURN_THROWS(); } fetchtype = MYSQLI_ASSOC; } else { if (override_flags) { if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &mysql_result, mysqli_result_class_entry) == FAILURE) { - return; + RETURN_THROWS(); } fetchtype = override_flags; } else { fetchtype = MYSQLI_BOTH; if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|l", &mysql_result, mysqli_result_class_entry, &fetchtype) == FAILURE) { - return; + RETURN_THROWS(); } } } diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 61a0de16d6..ad98bc6321 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -96,7 +96,7 @@ PHPAPI zend_class_entry *reflection_reference_ptr; return; \ } \ zend_throw_error(NULL, "Internal error: Failed to retrieve the reflection object"); \ - return; \ + RETURN_THROWS(); \ } \ } while (0) diff --git a/ext/session/session.c b/ext/session/session.c index 0b95af0232..03a53641dc 100644 --- a/ext/session/session.c +++ b/ext/session/session.c @@ -2221,14 +2221,14 @@ static PHP_FUNCTION(session_regenerate_id) if (PS(mod)->s_open(&PS(mod_data), PS(save_path), PS(session_name)) == FAILURE) { PS(session_status) = php_session_none; zend_throw_error(NULL, "Failed to open session: %s (path: %s)", PS(mod)->s_name, PS(save_path)); - RETURN_FALSE; + RETURN_THROWS(); } PS(id) = PS(mod)->s_create_sid(&PS(mod_data)); if (!PS(id)) { PS(session_status) = php_session_none; zend_throw_error(NULL, "Failed to create new session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); - RETURN_FALSE; + RETURN_THROWS(); } if (PS(use_strict_mode) && PS(mod)->s_validate_sid && PS(mod)->s_validate_sid(&PS(mod_data), PS(id)) == FAILURE) { @@ -2238,7 +2238,7 @@ static PHP_FUNCTION(session_regenerate_id) PS(mod)->s_close(&PS(mod_data)); PS(session_status) = php_session_none; zend_throw_error(NULL, "Failed to create session ID by collision: %s (path: %s)", PS(mod)->s_name, PS(save_path)); - RETURN_FALSE; + RETURN_THROWS(); } } /* Read is required to make new session data at this point. */ @@ -2246,7 +2246,7 @@ static PHP_FUNCTION(session_regenerate_id) PS(mod)->s_close(&PS(mod_data)); PS(session_status) = php_session_none; zend_throw_error(NULL, "Failed to create(read) session ID: %s (path: %s)", PS(mod)->s_name, PS(save_path)); - RETURN_FALSE; + RETURN_THROWS(); } if (data) { zend_string_release_ex(data, 0); diff --git a/ext/standard/array.c b/ext/standard/array.c index f8d4256aee..4fbd5506ea 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -3173,7 +3173,7 @@ PHP_FUNCTION(array_push) if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var) == NULL) { Z_TRY_DELREF(new_var); zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied"); - return; + RETURN_THROWS(); } } diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 59e31b5e62..8f1907f3be 100755 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -2341,7 +2341,7 @@ PHP_FUNCTION(forward_static_call) if (!EX(prev_execute_data)->func->common.scope) { zend_throw_error(NULL, "Cannot call forward_static_call() when no class scope is active"); - return; + RETURN_THROWS(); } fci.retval = &retval; diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 2e4637e78c..2ef8344aed 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -68,7 +68,7 @@ static zend_class_entry *dir_class_entry_ptr; if (myself) { \ if ((tmp = zend_hash_str_find(Z_OBJPROP_P(myself), "handle", sizeof("handle")-1)) == NULL) { \ zend_throw_error(NULL, "Unable to find my handle property"); \ - return; \ + RETURN_THROWS(); \ } \ if ((dirp = (php_stream *)zend_fetch_resource_ex(tmp, "Directory", php_file_le_stream())) == NULL) { \ return; \