diff options
author | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-01-02 10:35:31 +0100 |
---|---|---|
committer | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-01-02 10:56:18 +0100 |
commit | 01a50778d1f67d038b3f23911c0b84bfe055d64f (patch) | |
tree | 3920485afb84a44a538d2f9cd01e0c1d8b6ba579 /ext | |
parent | a6486088f8c98210b5676cd6fe337e205f6504b9 (diff) | |
download | php-git-01a50778d1f67d038b3f23911c0b84bfe055d64f.tar.gz |
Use RETURN_THROWS() after zend_throw_exception() in most of the extensions
Diffstat (limited to 'ext')
-rw-r--r-- | ext/json/json.c | 2 | ||||
-rw-r--r-- | ext/mysqli/mysqli.c | 2 | ||||
-rw-r--r-- | ext/pdo/pdo_dbh.c | 18 | ||||
-rw-r--r-- | ext/pgsql/pgsql.c | 2 | ||||
-rw-r--r-- | ext/phar/phar_object.c | 315 | ||||
-rw-r--r-- | ext/simplexml/simplexml.c | 8 | ||||
-rw-r--r-- | ext/snmp/snmp.c | 2 | ||||
-rw-r--r-- | ext/sodium/libsodium.c | 386 | ||||
-rw-r--r-- | ext/spl/spl_array.c | 4 | ||||
-rw-r--r-- | ext/spl/spl_directory.c | 36 | ||||
-rw-r--r-- | ext/spl/spl_dllist.c | 26 | ||||
-rw-r--r-- | ext/spl/spl_fixedarray.c | 8 | ||||
-rw-r--r-- | ext/spl/spl_heap.c | 22 | ||||
-rw-r--r-- | ext/spl/spl_iterators.c | 42 | ||||
-rw-r--r-- | ext/spl/spl_observer.c | 12 | ||||
-rw-r--r-- | ext/sqlite3/sqlite3.c | 8 | ||||
-rw-r--r-- | ext/standard/array.c | 16 | ||||
-rw-r--r-- | ext/standard/math.c | 4 | ||||
-rw-r--r-- | ext/standard/random.c | 6 |
19 files changed, 462 insertions, 457 deletions
diff --git a/ext/json/json.c b/ext/json/json.c index 4645309741..06e485bfe4 100644 --- a/ext/json/json.c +++ b/ext/json/json.c @@ -268,7 +268,7 @@ static PHP_FUNCTION(json_encode) if (encoder.error_code != PHP_JSON_ERROR_NONE) { smart_str_free(&buf); zend_throw_exception(php_json_exception_ce, php_json_get_error_msg(encoder.error_code), encoder.error_code); - RETURN_FALSE; + RETURN_THROWS(); } } diff --git a/ext/mysqli/mysqli.c b/ext/mysqli/mysqli.c index a4baa58dcb..f036bc7c47 100644 --- a/ext/mysqli/mysqli.c +++ b/ext/mysqli/mysqli.c @@ -1267,7 +1267,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags * argument passed by reference. */ zend_throw_exception(zend_ce_exception, "Parameter ctor_params must be an array", 0); - return; + RETURN_THROWS(); } } diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 22292181b4..b84eeb223e 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -226,7 +226,7 @@ static PHP_METHOD(PDO, dbh_constructor) snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source); if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) { zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name"); - return; + RETURN_THROWS(); } data_source = ini_dsn; @@ -234,7 +234,7 @@ static PHP_METHOD(PDO, dbh_constructor) if (!colon) { zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via INI: %s)", alt_dsn); - return; + RETURN_THROWS(); } } @@ -243,12 +243,12 @@ static PHP_METHOD(PDO, dbh_constructor) data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn)); if (!data_source) { zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI"); - return; + RETURN_THROWS(); } colon = strchr(data_source, ':'); if (!colon) { zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via URI)"); - return; + RETURN_THROWS(); } } @@ -258,7 +258,7 @@ static PHP_METHOD(PDO, dbh_constructor) /* NB: don't want to include the data_source in the error message as * it might contain a password */ zend_throw_exception_ex(php_pdo_get_exception(), 0, "could not find driver"); - return; + RETURN_THROWS(); } dbh = Z_PDO_DBH_P(object); @@ -567,14 +567,14 @@ static PHP_METHOD(PDO, beginTransaction) if (dbh->in_txn) { zend_throw_exception_ex(php_pdo_get_exception(), 0, "There is already an active transaction"); - RETURN_FALSE; + RETURN_THROWS(); } if (!dbh->methods->begin) { /* TODO: this should be an exception; see the auto-commit mode * comments below */ zend_throw_exception_ex(php_pdo_get_exception(), 0, "This driver doesn't support transactions"); - RETURN_FALSE; + RETURN_THROWS(); } if (dbh->methods->begin(dbh)) { @@ -600,7 +600,7 @@ static PHP_METHOD(PDO, commit) if (!dbh->in_txn) { zend_throw_exception_ex(php_pdo_get_exception(), 0, "There is no active transaction"); - RETURN_FALSE; + RETURN_THROWS(); } if (dbh->methods->commit(dbh)) { @@ -626,7 +626,7 @@ static PHP_METHOD(PDO, rollBack) if (!dbh->in_txn) { zend_throw_exception_ex(php_pdo_get_exception(), 0, "There is no active transaction"); - RETURN_FALSE; + RETURN_THROWS(); } if (dbh->methods->rollback(dbh)) { diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index c95f47770c..3445860f77 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2840,7 +2840,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_ * argument passed by reference. */ zend_throw_exception(zend_ce_exception, "Parameter ctor_params must be an array", 0); - return; + RETURN_THROWS(); } } diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index f731a57031..4182d41cd3 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -686,7 +686,7 @@ PHP_METHOD(Phar, webPhar) } efree(pt); - return; + RETURN_THROWS(); } fci.param_count = 1; @@ -704,7 +704,7 @@ PHP_METHOD(Phar, webPhar) } efree(pt); - return; + RETURN_THROWS(); } if (Z_TYPE_P(fci.retval) == IS_UNDEF || Z_TYPE(retval) == IS_UNDEF) { @@ -713,7 +713,7 @@ PHP_METHOD(Phar, webPhar) } zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: rewrite callback must return a string or false"); efree(pt); - return; + RETURN_THROWS(); } switch (Z_TYPE(retval)) { @@ -740,7 +740,7 @@ PHP_METHOD(Phar, webPhar) efree(pt); zend_throw_exception_ex(phar_ce_PharException, 0, "phar error: rewrite callback must return a string or false"); - return; + RETURN_THROWS(); } } @@ -842,7 +842,7 @@ PHP_METHOD(Phar, webPhar) #ifdef PHP_WIN32 efree(fname); #endif - RETURN_FALSE; + RETURN_THROWS(); } break; case IS_STRING: @@ -859,7 +859,7 @@ PHP_METHOD(Phar, webPhar) #ifdef PHP_WIN32 efree(fname); #endif - RETURN_FALSE; + RETURN_THROWS(); } } } @@ -888,12 +888,12 @@ PHP_METHOD(Phar, mungServer) if (!zend_hash_num_elements(Z_ARRVAL_P(mungvalues))) { zend_throw_exception_ex(phar_ce_PharException, 0, "No values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME"); - return; + RETURN_THROWS(); } if (zend_hash_num_elements(Z_ARRVAL_P(mungvalues)) > 4) { zend_throw_exception_ex(phar_ce_PharException, 0, "Too many values passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME"); - return; + RETURN_THROWS(); } phar_request_initialize(); @@ -902,7 +902,7 @@ PHP_METHOD(Phar, mungServer) if (Z_TYPE_P(data) != IS_STRING) { zend_throw_exception_ex(phar_ce_PharException, 0, "Non-string value passed to Phar::mungServer(), expecting an array of any of these strings: PHP_SELF, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME"); - return; + RETURN_THROWS(); } if (Z_STRLEN_P(data) == sizeof("PHP_SELF")-1 && !strncmp(Z_STRVAL_P(data), "PHP_SELF", sizeof("PHP_SELF")-1)) { @@ -962,7 +962,7 @@ PHP_METHOD(Phar, createDefaultStub) if (error) { zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); - return; + RETURN_THROWS(); } RETURN_NEW_STR(stub); } @@ -1157,7 +1157,7 @@ PHP_METHOD(Phar, __construct) if (phar_obj->archive) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot call constructor twice"); - return; + RETURN_THROWS(); } save_fname = fname; @@ -1198,7 +1198,7 @@ PHP_METHOD(Phar, __construct) "Phar creation or opening failed"); } - return; + RETURN_THROWS(); } if (is_data && phar_data->is_tar && phar_data->is_brandnew && format == PHAR_FORMAT_ZIP) { @@ -1220,7 +1220,7 @@ PHP_METHOD(Phar, __construct) "Phar class can only be used for executable tar and zip archives"); } efree(entry); - return; + RETURN_THROWS(); } is_data = phar_data->is_data; @@ -1322,7 +1322,7 @@ PHP_METHOD(Phar, unlinkArchive) if (!fname_len) { zend_throw_exception_ex(phar_ce_PharException, 0, "Unknown phar archive \"\""); - return; + RETURN_THROWS(); } if (FAILURE == phar_open_from_filename(fname, fname_len, NULL, 0, REPORT_ERRORS, &phar, &error)) { @@ -1332,7 +1332,7 @@ PHP_METHOD(Phar, unlinkArchive) } else { zend_throw_exception_ex(phar_ce_PharException, 0, "Unknown phar archive \"%s\"", fname); } - return; + RETURN_THROWS(); } zname = (char*)zend_get_executed_filename(); @@ -1343,7 +1343,7 @@ PHP_METHOD(Phar, unlinkArchive) zend_throw_exception_ex(phar_ce_PharException, 0, "phar archive \"%s\" cannot be unlinked from within itself", fname); efree(arch); efree(entry); - return; + RETURN_THROWS(); } efree(arch); efree(entry); @@ -1351,12 +1351,12 @@ PHP_METHOD(Phar, unlinkArchive) if (phar->is_persistent) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar archive \"%s\" is in phar.cache_list, cannot unlinkArchive()", fname); - return; + RETURN_THROWS(); } if (phar->refcount) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar archive \"%s\" has open file handles or objects. fclose() all file handles, and unset() all objects prior to calling unlinkArchive()", fname); - return; + RETURN_THROWS(); } fname = estrndup(phar->fname, phar->fname_len); @@ -1378,7 +1378,7 @@ PHP_METHOD(Phar, unlinkArchive) if (!phar_obj->archive) { \ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \ "Cannot call method on an uninitialized Phar object"); \ - return; \ + RETURN_THROWS(); \ } /* {{{ proto Phar::__destruct() @@ -1733,7 +1733,7 @@ PHP_METHOD(Phar, buildFromDirectory) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot write to archive - write operations restricted by INI setting"); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|s", &dir, &dir_len, ®ex, ®ex_len) == FAILURE) { @@ -1747,7 +1747,7 @@ PHP_METHOD(Phar, buildFromDirectory) if (SUCCESS != object_init_ex(&iter, spl_ce_RecursiveDirectoryIterator)) { zval_ptr_dtor(&iter); zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unable to instantiate directory iterator for %s", phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } ZVAL_STRINGL(&arg, dir, dir_len); @@ -1766,7 +1766,7 @@ PHP_METHOD(Phar, buildFromDirectory) zval_ptr_dtor(&iter); zval_ptr_dtor(&iteriter); zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unable to instantiate directory iterator for %s", phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } zend_call_method_with_1_params(Z_OBJ(iteriter), spl_ce_RecursiveIteratorIterator, @@ -1787,7 +1787,7 @@ PHP_METHOD(Phar, buildFromDirectory) zval_ptr_dtor(&iteriter); zval_ptr_dtor(®exiter); zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unable to instantiate regex iterator for %s", phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } ZVAL_STRINGL(&arg2, regex, regex_len); @@ -1808,7 +1808,7 @@ PHP_METHOD(Phar, buildFromDirectory) pass.fp = php_stream_fopen_tmpfile(); if (pass.fp == NULL) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" unable to create temporary file", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { @@ -1818,7 +1818,7 @@ PHP_METHOD(Phar, buildFromDirectory) } php_stream_close(pass.fp); zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (SUCCESS == spl_iterator_apply((apply_reg ? ®exiter : &iteriter), (spl_iterator_apply_func_t) phar_build, (void *) &pass)) { @@ -1869,7 +1869,7 @@ PHP_METHOD(Phar, buildFromIterator) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot write out phar archive, phar is read-only"); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s", &obj, zend_ce_traversable, &base, &base_len) == FAILURE) { @@ -1882,7 +1882,7 @@ PHP_METHOD(Phar, buildFromIterator) if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } array_init(return_value); @@ -1896,7 +1896,7 @@ PHP_METHOD(Phar, buildFromIterator) pass.fp = php_stream_fopen_tmpfile(); if (pass.fp == NULL) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\": unable to create temporary file", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (SUCCESS == spl_iterator_apply(obj, (spl_iterator_apply_func_t) phar_build, (void *) &pass)) { @@ -2388,7 +2388,7 @@ PHP_METHOD(Phar, convertToExecutable) if (PHAR_G(readonly)) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot write out executable phar archive, phar is read-only"); - return; + RETURN_THROWS(); } switch (format) { @@ -2410,7 +2410,7 @@ PHP_METHOD(Phar, convertToExecutable) default: zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unknown file format specified, please pass one of Phar::PHAR, Phar::TAR or Phar::ZIP"); - return; + RETURN_THROWS(); } switch (method) { @@ -2424,13 +2424,13 @@ PHP_METHOD(Phar, convertToExecutable) if (format == PHAR_FORMAT_ZIP) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with gzip, zip archives do not support whole-archive compression"); - return; + RETURN_THROWS(); } if (!PHAR_G(has_zlib)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with gzip, enable ext/zlib in php.ini"); - return; + RETURN_THROWS(); } flags = PHAR_FILE_COMPRESSED_GZ; @@ -2439,13 +2439,13 @@ PHP_METHOD(Phar, convertToExecutable) if (format == PHAR_FORMAT_ZIP) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with bz2, zip archives do not support whole-archive compression"); - return; + RETURN_THROWS(); } if (!PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with bz2, enable ext/bz2 in php.ini"); - return; + RETURN_THROWS(); } flags = PHAR_FILE_COMPRESSED_BZ2; @@ -2453,7 +2453,7 @@ PHP_METHOD(Phar, convertToExecutable) default: zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2"); - return; + RETURN_THROWS(); } is_data = phar_obj->archive->is_data; @@ -2500,20 +2500,20 @@ PHP_METHOD(Phar, convertToData) } else { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot write out data phar archive, use Phar::TAR or Phar::ZIP"); - return; + RETURN_THROWS(); } break; case PHAR_FORMAT_PHAR: zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot write out data phar archive, use Phar::TAR or Phar::ZIP"); - return; + RETURN_THROWS(); case PHAR_FORMAT_TAR: case PHAR_FORMAT_ZIP: break; default: zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unknown file format specified, please pass one of Phar::TAR or Phar::ZIP"); - return; + RETURN_THROWS(); } switch (method) { @@ -2527,13 +2527,13 @@ PHP_METHOD(Phar, convertToData) if (format == PHAR_FORMAT_ZIP) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with gzip, zip archives do not support whole-archive compression"); - return; + RETURN_THROWS(); } if (!PHAR_G(has_zlib)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with gzip, enable ext/zlib in php.ini"); - return; + RETURN_THROWS(); } flags = PHAR_FILE_COMPRESSED_GZ; @@ -2542,13 +2542,13 @@ PHP_METHOD(Phar, convertToData) if (format == PHAR_FORMAT_ZIP) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with bz2, zip archives do not support whole-archive compression"); - return; + RETURN_THROWS(); } if (!PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with bz2, enable ext/bz2 in php.ini"); - return; + RETURN_THROWS(); } flags = PHAR_FILE_COMPRESSED_BZ2; @@ -2556,7 +2556,7 @@ PHP_METHOD(Phar, convertToData) default: zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2"); - return; + RETURN_THROWS(); } is_data = phar_obj->archive->is_data; @@ -2638,7 +2638,7 @@ PHP_METHOD(Phar, delete) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot write out phar archive, phar is read-only"); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) { @@ -2647,7 +2647,7 @@ PHP_METHOD(Phar, delete) if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (zend_hash_str_exists(&phar_obj->archive->manifest, fname, (uint32_t) fname_len)) { if (NULL != (entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len))) { @@ -2662,13 +2662,14 @@ PHP_METHOD(Phar, delete) } } else { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Entry %s does not exist and cannot be deleted", fname); - RETURN_FALSE; + RETURN_THROWS(); } phar_flush(phar_obj->archive, NULL, 0, 0, &error); if (error) { zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); + RETURN_THROWS(); } RETURN_TRUE; @@ -2723,7 +2724,7 @@ PHP_METHOD(Phar, setAlias) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot write out phar archive, phar is read-only"); - RETURN_FALSE; + RETURN_THROWS(); } /* invalidate phar cache */ @@ -2738,7 +2739,7 @@ PHP_METHOD(Phar, setAlias) zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "A Phar alias cannot be set in a plain zip archive"); } - RETURN_FALSE; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &alias, &alias_len) == SUCCESS) { @@ -2753,17 +2754,17 @@ PHP_METHOD(Phar, setAlias) } zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); - RETURN_FALSE; + RETURN_THROWS(); } if (!phar_validate_alias(alias, alias_len)) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Invalid alias \"%s\" specified for phar \"%s\"", alias, phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } valid_alias: if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (phar_obj->archive->alias_len && NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), phar_obj->archive->alias, phar_obj->archive->alias_len))) { zend_hash_str_del(&(PHAR_G(phar_alias_map)), phar_obj->archive->alias, phar_obj->archive->alias_len); @@ -2793,7 +2794,7 @@ valid_alias: zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), oldalias, oldalias_len, phar_obj->archive); } efree(error); - RETURN_FALSE; + RETURN_THROWS(); } zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), alias, alias_len, phar_obj->archive); @@ -2870,7 +2871,7 @@ PHP_METHOD(Phar, stopBuffering) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot write out phar archive, phar is read-only"); - return; + RETURN_THROWS(); } phar_obj->archive->donotflush = 0; @@ -2899,7 +2900,7 @@ PHP_METHOD(Phar, setStub) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot change stub, phar is read-only"); - return; + RETURN_THROWS(); } if (phar_obj->archive->is_data) { @@ -2910,7 +2911,7 @@ PHP_METHOD(Phar, setStub) zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "A Phar stub cannot be set in a plain zip archive"); } - return; + RETURN_THROWS(); } if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "r|l", &zstub, &len) == SUCCESS) { @@ -2922,7 +2923,7 @@ PHP_METHOD(Phar, setStub) } if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } phar_flush(phar_obj->archive, (char *) zstub, len, 0, &error); if (error) { @@ -2937,13 +2938,14 @@ PHP_METHOD(Phar, setStub) } else if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &stub, &stub_len) == SUCCESS) { if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } phar_flush(phar_obj->archive, stub, stub_len, 0, &error); if (error) { zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); + RETURN_THROWS(); } RETURN_TRUE; @@ -2982,7 +2984,7 @@ PHP_METHOD(Phar, setDefaultStub) zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "A Phar stub cannot be set in a plain zip archive"); } - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s", &index, &index_len, &webindex, &webindex_len) == FAILURE) { @@ -2997,7 +2999,7 @@ PHP_METHOD(Phar, setDefaultStub) if (PHAR_G(readonly)) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot change stub: phar.readonly=1"); - RETURN_FALSE; + RETURN_THROWS(); } if (!phar_obj->archive->is_tar && !phar_obj->archive->is_zip) { @@ -3009,7 +3011,7 @@ PHP_METHOD(Phar, setDefaultStub) if (stub) { zend_string_free(stub); } - RETURN_FALSE; + RETURN_THROWS(); } created_stub = 1; @@ -3017,7 +3019,7 @@ PHP_METHOD(Phar, setDefaultStub) if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } phar_flush(phar_obj->archive, stub ? ZSTR_VAL(stub) : 0, stub ? ZSTR_LEN(stub) : 0, 1, &error); @@ -3028,7 +3030,7 @@ PHP_METHOD(Phar, setDefaultStub) if (error) { zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); - RETURN_FALSE; + RETURN_THROWS(); } RETURN_TRUE; @@ -3052,7 +3054,7 @@ PHP_METHOD(Phar, setSignatureAlgorithm) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot set signature algorithm, phar is read-only"); - return; + RETURN_THROWS(); } if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "l|s", &algo, &key, &key_len) != SUCCESS) { @@ -3067,7 +3069,7 @@ PHP_METHOD(Phar, setSignatureAlgorithm) case PHAR_SIG_OPENSSL: if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } phar_obj->archive->sig_flags = (php_uint32)algo; phar_obj->archive->is_modified = 1; @@ -3223,13 +3225,13 @@ PHP_METHOD(Phar, compress) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot compress phar archive, phar is read-only"); - return; + RETURN_THROWS(); } if (phar_obj->archive->is_zip) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot compress zip-based archives with whole-archive compression"); - return; + RETURN_THROWS(); } switch (method) { @@ -3240,7 +3242,7 @@ PHP_METHOD(Phar, compress) if (!PHAR_G(has_zlib)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress entire archive with gzip, enable ext/zlib in php.ini"); - return; + RETURN_THROWS(); } flags = PHAR_FILE_COMPRESSED_GZ; break; @@ -3256,7 +3258,7 @@ PHP_METHOD(Phar, compress) default: zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2"); - return; + RETURN_THROWS(); } if (phar_obj->archive->is_tar) { @@ -3290,13 +3292,13 @@ PHP_METHOD(Phar, decompress) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot decompress phar archive, phar is read-only"); - return; + RETURN_THROWS(); } if (phar_obj->archive->is_zip) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot decompress zip-based archives with whole-archive compression"); - return; + RETURN_THROWS(); } if (phar_obj->archive->is_tar) { @@ -3332,7 +3334,7 @@ PHP_METHOD(Phar, compressFiles) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar is readonly, cannot change compression"); - return; + RETURN_THROWS(); } switch (method) { @@ -3340,7 +3342,7 @@ PHP_METHOD(Phar, compressFiles) if (!PHAR_G(has_zlib)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress files within archive with gzip, enable ext/zlib in php.ini"); - return; + RETURN_THROWS(); } flags = PHAR_ENT_COMPRESSED_GZ; break; @@ -3349,20 +3351,20 @@ PHP_METHOD(Phar, compressFiles) if (!PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress files within archive with bz2, enable ext/bz2 in php.ini"); - return; + RETURN_THROWS(); } flags = PHAR_ENT_COMPRESSED_BZ2; break; default: zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2"); - return; + RETURN_THROWS(); } if (phar_obj->archive->is_tar) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress with Gzip compression, tar archives cannot compress individual files, use compress() to compress the whole archive"); - return; + RETURN_THROWS(); } if (!pharobj_cancompress(&phar_obj->archive->manifest)) { @@ -3373,12 +3375,12 @@ PHP_METHOD(Phar, compressFiles) zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress all files as Bzip2, some are compressed as gzip and cannot be decompressed"); } - return; + RETURN_THROWS(); } if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } pharobj_set_compression(&phar_obj->archive->manifest, flags); phar_obj->archive->is_modified = 1; @@ -3406,13 +3408,13 @@ PHP_METHOD(Phar, decompressFiles) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar is readonly, cannot change compression"); - return; + RETURN_THROWS(); } if (!pharobj_cancompress(&phar_obj->archive->manifest)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot decompress all files, some are compressed as bzip2 or gzip and cannot be decompressed"); - return; + RETURN_THROWS(); } if (phar_obj->archive->is_tar) { @@ -3420,7 +3422,7 @@ PHP_METHOD(Phar, decompressFiles) } else { if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } pharobj_set_compression(&phar_obj->archive->manifest, PHAR_ENT_COMPRESSED_NONE); } @@ -3456,34 +3458,34 @@ PHP_METHOD(Phar, copy) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot copy \"%s\" to \"%s\", phar is read-only", oldfile, newfile); - RETURN_FALSE; + RETURN_THROWS(); } if (oldfile_len >= sizeof(".phar")-1 && !memcmp(oldfile, ".phar", sizeof(".phar")-1)) { /* can't copy a meta file */ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "file \"%s\" cannot be copied to file \"%s\", cannot copy Phar meta-file in %s", oldfile, newfile, phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } if (newfile_len >= sizeof(".phar")-1 && !memcmp(newfile, ".phar", sizeof(".phar")-1)) { /* can't copy a meta file */ zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "file \"%s\" cannot be copied to file \"%s\", cannot copy to Phar meta-file in %s", oldfile, newfile, phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } if (!zend_hash_str_exists(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len) || NULL == (oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len)) || oldentry->is_deleted) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "file \"%s\" cannot be copied to file \"%s\", file does not exist in %s", oldfile, newfile, phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } if (zend_hash_str_exists(&phar_obj->archive->manifest, newfile, (uint32_t) newfile_len)) { if (NULL != (temp = zend_hash_str_find_ptr(&phar_obj->archive->manifest, newfile, (uint32_t) newfile_len)) || !temp->is_deleted) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "file \"%s\" cannot be copied to file \"%s\", file must not already exist in phar %s", oldfile, newfile, phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } } @@ -3491,14 +3493,14 @@ PHP_METHOD(Phar, copy) if (phar_path_check(&newfile, &tmp_len, &pcr_error) > pcr_is_ok) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "file \"%s\" contains invalid characters %s, cannot be copied from \"%s\" in phar %s", newfile, pcr_error, oldfile, phar_obj->archive->fname); - RETURN_FALSE; + RETURN_THROWS(); } newfile_len = tmp_len; if (phar_obj->archive->is_persistent) { if (FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } /* re-populate with copied-on-write entry */ oldentry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, oldfile, (uint32_t) oldfile_len); @@ -3521,7 +3523,7 @@ PHP_METHOD(Phar, copy) php_stream_close(newentry.fp); zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); - return; + RETURN_THROWS(); } } @@ -3597,17 +3599,17 @@ PHP_METHOD(Phar, offsetGet) } else { if (fname_len == sizeof(".phar/stub.php")-1 && !memcmp(fname, ".phar/stub.php", sizeof(".phar/stub.php")-1)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot get stub \".phar/stub.php\" directly in phar \"%s\", use getStub", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (fname_len == sizeof(".phar/alias.txt")-1 && !memcmp(fname, ".phar/alias.txt", sizeof(".phar/alias.txt")-1)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot get alias \".phar/alias.txt\" directly in phar \"%s\", use getAlias", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (fname_len >= sizeof(".phar")-1 && !memcmp(fname, ".phar", sizeof(".phar")-1)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot directly get any files or directories in magic \".phar\" directory"); - return; + RETURN_THROWS(); } if (entry->is_temp_dir) { @@ -3767,7 +3769,7 @@ PHP_METHOD(Phar, offsetSet) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly"); - return; + RETURN_THROWS(); } if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "pr", &fname, &fname_len, &zresource) == FAILURE @@ -3776,17 +3778,17 @@ PHP_METHOD(Phar, offsetSet) } if (fname_len == sizeof(".phar/stub.php")-1 && !memcmp(fname, ".phar/stub.php", sizeof(".phar/stub.php")-1)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot set stub \".phar/stub.php\" directly in phar \"%s\", use setStub", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (fname_len == sizeof(".phar/alias.txt")-1 && !memcmp(fname, ".phar/alias.txt", sizeof(".phar/alias.txt")-1)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot set alias \".phar/alias.txt\" directly in phar \"%s\", use setAlias", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (fname_len >= sizeof(".phar")-1 && !memcmp(fname, ".phar", sizeof(".phar")-1)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot set any files or directories in magic \".phar\" directory"); - return; + RETURN_THROWS(); } phar_add_file(&(phar_obj->archive), fname, fname_len, cont_str, cont_len, zresource); @@ -3805,7 +3807,7 @@ PHP_METHOD(Phar, offsetUnset) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly"); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &fname, &fname_len) == FAILURE) { @@ -3822,7 +3824,7 @@ PHP_METHOD(Phar, offsetUnset) if (phar_obj->archive->is_persistent) { if (FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } /* re-populate entry after copy on write */ entry = zend_hash_str_find_ptr(&phar_obj->archive->manifest, fname, (uint32_t) fname_len); @@ -3861,7 +3863,7 @@ PHP_METHOD(Phar, addEmptyDir) if (dirname_len >= sizeof(".phar")-1 && !memcmp(dirname, ".phar", sizeof(".phar")-1)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot create a directory in magic \".phar\" directory"); - return; + RETURN_THROWS(); } phar_mkdir(&phar_obj->archive, dirname, dirname_len); @@ -3886,12 +3888,12 @@ PHP_METHOD(Phar, addFile) if (!strstr(fname, "://") && php_check_open_basedir(fname)) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "phar error: unable to open file \"%s\" to add to phar archive, open_basedir restrictions prevent this", fname); - return; + RETURN_THROWS(); } if (!(resource = php_stream_open_wrapper(fname, "rb", 0, NULL))) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "phar error: unable to open file \"%s\" to add to phar archive", fname); - return; + RETURN_THROWS(); } if (localname) { @@ -3948,7 +3950,7 @@ PHP_METHOD(Phar, getStub) } else { if (!(fp = php_stream_open_wrapper(phar_obj->archive->fname, "rb", 0, NULL))) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "phar error: unable to open phar \"%s\"", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (stub->flags & PHAR_ENT_COMPRESSION_MASK) { char *filter_name; @@ -3960,7 +3962,7 @@ PHP_METHOD(Phar, getStub) } if (!filter) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "phar error: unable to read stub of phar \"%s\" (cannot create %s filter)", phar_obj->archive->fname, phar_decompress_filter(stub, 1)); - return; + RETURN_THROWS(); } php_stream_filter_append(&fp->readfilters, filter); } @@ -3969,7 +3971,7 @@ PHP_METHOD(Phar, getStub) if (!fp) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Unable to read stub"); - return; + RETURN_THROWS(); } php_stream_seek(fp, stub->offset_abs, SEEK_SET); @@ -3990,7 +3992,7 @@ PHP_METHOD(Phar, getStub) if (!fp) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Unable to read stub"); - return; + RETURN_THROWS(); } php_stream_rewind(fp); @@ -4004,7 +4006,7 @@ carry_on: zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Unable to read stub"); zend_string_release_ex(buf, 0); - return; + RETURN_THROWS(); } if (filter) { @@ -4073,7 +4075,7 @@ PHP_METHOD(Phar, setMetadata) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly"); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &metadata) == FAILURE) { @@ -4082,7 +4084,7 @@ PHP_METHOD(Phar, setMetadata) if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname); - return; + RETURN_THROWS(); } if (Z_TYPE(phar_obj->archive->metadata) != IS_UNDEF) { zval_ptr_dtor(&phar_obj->archive->metadata); @@ -4111,7 +4113,7 @@ PHP_METHOD(Phar, delMetadata) if (PHAR_G(readonly) && !phar_obj->archive->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly"); - return; + RETURN_THROWS(); } if (zend_parse_parameters_none() == FAILURE) { @@ -4127,7 +4129,7 @@ PHP_METHOD(Phar, delMetadata) if (error) { zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); - RETURN_FALSE; + RETURN_THROWS(); } else { RETURN_TRUE; } @@ -4376,7 +4378,7 @@ PHP_METHOD(Phar, extractTo) if (!fp) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid argument, %s cannot be found", phar_obj->archive->fname); - return; + RETURN_THROWS(); } php_stream_close(fp); @@ -4384,7 +4386,7 @@ PHP_METHOD(Phar, extractTo) if (pathto_len < 1) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid argument, extraction path must be non-zero length"); - return; + RETURN_THROWS(); } if (pathto_len >= MAXPATHLEN) { @@ -4392,7 +4394,7 @@ PHP_METHOD(Phar, extractTo) /* truncate for error message */ zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Cannot extract to \"%s...\", destination directory is too long for filesystem", tmp); efree(tmp); - return; + RETURN_THROWS(); } if (php_stream_stat_path(pathto, &ssb) < 0) { @@ -4400,12 +4402,12 @@ PHP_METHOD(Phar, extractTo) if (!ret) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Unable to create path \"%s\" for extraction", pathto); - return; + RETURN_THROWS(); } } else if (!(ssb.sb.st_mode & S_IFDIR)) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Unable to use path \"%s\" for extraction, it is a file, must be a directory", pathto); - return; + RETURN_THROWS(); } if (zval_files) { @@ -4426,26 +4428,26 @@ PHP_METHOD(Phar, extractTo) if (IS_STRING != Z_TYPE_P(zval_file)) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid argument, array of filenames to extract contains non-string value"); - return; + RETURN_THROWS(); } switch (extract_helper(phar_obj->archive, Z_STR_P(zval_file), pathto, pathto_len, overwrite, &error)) { case -1: zend_throw_exception_ex(phar_ce_PharException, 0, "Extraction from phar \"%s\" failed: %s", phar_obj->archive->fname, error); efree(error); - return; + RETURN_THROWS(); case 0: zend_throw_exception_ex(phar_ce_PharException, 0, "Phar Error: attempted to extract non-existent file or directory \"%s\" from phar \"%s\"", ZSTR_VAL(Z_STR_P(zval_file)), phar_obj->archive->fname); - return; + RETURN_THROWS(); } } ZEND_HASH_FOREACH_END(); RETURN_TRUE; default: zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Invalid argument, expected a filename (string) or array of filenames"); - return; + RETURN_THROWS(); } } else { filename = NULL; @@ -4488,13 +4490,13 @@ PHP_METHOD(PharFileInfo, __construct) if (entry_obj->entry) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot call constructor twice"); - return; + RETURN_THROWS(); } if (fname_len < 7 || memcmp(fname, "phar://", 7) || phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, 2, 0) == FAILURE) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "'%s' is not a valid phar archive URL (must have at least phar://filename.phar)", fname); - return; + RETURN_THROWS(); } if (phar_open_from_filename(arch, arch_len, NULL, 0, REPORT_ERRORS, &phar_data, &error) == FAILURE) { @@ -4508,7 +4510,7 @@ PHP_METHOD(PharFileInfo, __construct) zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot open phar file '%s'", fname); } - return; + RETURN_THROWS(); } if ((entry_info = phar_get_entry_info_dir(phar_data, entry, entry_len, 1, &error, 1)) == NULL) { @@ -4516,7 +4518,7 @@ PHP_METHOD(PharFileInfo, __construct) "Cannot access phar file entry '%s' in archive '%s'%s%s", entry, arch, error ? ", " : "", error ? error : ""); efree(arch); efree(entry); - return; + RETURN_THROWS(); } efree(arch); @@ -4539,7 +4541,7 @@ PHP_METHOD(PharFileInfo, __construct) if (!entry_obj->entry) { \ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \ "Cannot call method on an uninitialized PharFileInfo object"); \ - return; \ + RETURN_THROWS(); \ } /* {{{ proto PharFileInfo::__destruct() @@ -4618,7 +4620,7 @@ PHP_METHOD(PharFileInfo, getCRC32) if (entry_obj->entry->is_dir) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \ "Phar entry is a directory, does not have a CRC"); \ - return; + RETURN_THROWS(); } if (entry_obj->entry->is_crc_checked) { @@ -4672,12 +4674,12 @@ PHP_METHOD(PharFileInfo, chmod) if (entry_obj->entry->is_temp_dir) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \ "Phar entry \"%s\" is a temporary directory (not an actual entry in the archive), cannot chmod", entry_obj->entry->filename); \ - return; + RETURN_THROWS(); } if (PHAR_G(readonly) && !entry_obj->entry->phar->is_data) { zend_throw_exception_ex(phar_ce_PharException, 0, "Cannot modify permissions for file \"%s\" in phar \"%s\", write operations are prohibited", entry_obj->entry->filename, entry_obj->entry->phar->fname); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &perms) == FAILURE) { @@ -4689,7 +4691,7 @@ PHP_METHOD(PharFileInfo, chmod) if (FAILURE == phar_copy_on_write(&phar)) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar->fname); - return; + RETURN_THROWS(); } /* re-populate after copy-on-write */ entry_obj->entry = zend_hash_str_find_ptr(&phar->manifest, entry_obj->entry->filename, entry_obj->entry->filename_len); @@ -4774,13 +4776,13 @@ PHP_METHOD(PharFileInfo, setMetadata) if (PHAR_G(readonly) && !entry_obj->entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly"); - return; + RETURN_THROWS(); } if (entry_obj->entry->is_temp_dir) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \ "Phar entry is a temporary directory (not an actual entry in the archive), cannot set metadata"); \ - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &metadata) == FAILURE) { @@ -4792,7 +4794,7 @@ PHP_METHOD(PharFileInfo, setMetadata) if (FAILURE == phar_copy_on_write(&phar)) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar->fname); - return; + RETURN_THROWS(); } /* re-populate after copy-on-write */ entry_obj->entry = zend_hash_str_find_ptr(&phar->manifest, entry_obj->entry->filename, entry_obj->entry->filename_len); @@ -4830,13 +4832,13 @@ PHP_METHOD(PharFileInfo, delMetadata) if (PHAR_G(readonly) && !entry_obj->entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Write operations disabled by the php.ini setting phar.readonly"); - return; + RETURN_THROWS(); } if (entry_obj->entry->is_temp_dir) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \ "Phar entry is a temporary directory (not an actual entry in the archive), cannot delete metadata"); \ - return; + RETURN_THROWS(); } if (Z_TYPE(entry_obj->entry->metadata) != IS_UNDEF) { @@ -4845,7 +4847,7 @@ PHP_METHOD(PharFileInfo, delMetadata) if (FAILURE == phar_copy_on_write(&phar)) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar->fname); - return; + RETURN_THROWS(); } /* re-populate after copy-on-write */ entry_obj->entry = zend_hash_str_find_ptr(&phar->manifest, entry_obj->entry->filename, entry_obj->entry->filename_len); @@ -4860,7 +4862,7 @@ PHP_METHOD(PharFileInfo, delMetadata) if (error) { zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); - RETURN_FALSE; + RETURN_THROWS(); } else { RETURN_TRUE; } @@ -4890,7 +4892,7 @@ PHP_METHOD(PharFileInfo, getContent) if (entry_obj->entry->is_dir) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar error: Cannot retrieve contents, \"%s\" in phar \"%s\" is a directory", entry_obj->entry->filename, entry_obj->entry->phar->fname); - return; + RETURN_THROWS(); } link = phar_get_link_source(entry_obj->entry); @@ -4903,13 +4905,13 @@ PHP_METHOD(PharFileInfo, getContent) zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar error: Cannot retrieve contents, \"%s\" in phar \"%s\": %s", entry_obj->entry->filename, entry_obj->entry->phar->fname, error); efree(error); - return; + RETURN_THROWS(); } if (!(fp = phar_get_efp(link, 0))) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar error: Cannot retrieve contents of \"%s\" in phar \"%s\"", entry_obj->entry->filename, entry_obj->entry->phar->fname); - return; + RETURN_THROWS(); } phar_seek_efp(link, 0, SEEK_SET, 0, 0); @@ -4938,25 +4940,25 @@ PHP_METHOD(PharFileInfo, compress) if (entry_obj->entry->is_tar) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress with Gzip compression, not possible with tar-based phar archives"); - return; + RETURN_THROWS(); } if (entry_obj->entry->is_dir) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \ "Phar entry is a directory, cannot set compression"); \ - return; + RETURN_THROWS(); } if (PHAR_G(readonly) && !entry_obj->entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar is readonly, cannot change compression"); - return; + RETURN_THROWS(); } if (entry_obj->entry->is_deleted) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress deleted file"); - return; + RETURN_THROWS(); } if (entry_obj->entry->is_persistent) { @@ -4964,7 +4966,7 @@ PHP_METHOD(PharFileInfo, compress) if (FAILURE == phar_copy_on_write(&phar)) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar->fname); - return; + RETURN_THROWS(); } /* re-populate after copy-on-write */ entry_obj->entry = zend_hash_str_find_ptr(&phar->manifest, entry_obj->entry->filename, entry_obj->entry->filename_len); @@ -4979,7 +4981,7 @@ PHP_METHOD(PharFileInfo, compress) if (!PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress with gzip compression, file is already compressed with bzip2 compression and bz2 extension is not enabled, cannot decompress"); - return; + RETURN_THROWS(); } /* decompress this file indirectly */ @@ -4987,14 +4989,14 @@ PHP_METHOD(PharFileInfo, compress) zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar error: Cannot decompress bzip2-compressed file \"%s\" in phar \"%s\" in order to compress with gzip: %s", entry_obj->entry->filename, entry_obj->entry->phar->fname, error); efree(error); - return; + RETURN_THROWS(); } } if (!PHAR_G(has_zlib)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress with gzip compression, zlib extension is not enabled"); - return; + RETURN_THROWS(); } entry_obj->entry->old_flags = entry_obj->entry->flags; @@ -5010,7 +5012,7 @@ PHP_METHOD(PharFileInfo, compress) if (!PHAR_G(has_zlib)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress with bzip2 compression, file is already compressed with gzip compression and zlib extension is not enabled, cannot decompress"); - return; + RETURN_THROWS(); } /* decompress this file indirectly */ @@ -5018,14 +5020,14 @@ PHP_METHOD(PharFileInfo, compress) zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar error: Cannot decompress gzip-compressed file \"%s\" in phar \"%s\" in order to compress with bzip2: %s", entry_obj->entry->filename, entry_obj->entry->phar->fname, error); efree(error); - return; + RETURN_THROWS(); } } if (!PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress with bzip2 compression, bz2 extension is not enabled"); - return; + RETURN_THROWS(); } entry_obj->entry->old_flags = entry_obj->entry->flags; entry_obj->entry->flags &= ~PHAR_ENT_COMPRESSION_MASK; @@ -5043,6 +5045,7 @@ PHP_METHOD(PharFileInfo, compress) if (error) { zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); + RETURN_THROWS(); } RETURN_TRUE; @@ -5064,7 +5067,7 @@ PHP_METHOD(PharFileInfo, decompress) if (entry_obj->entry->is_dir) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, \ "Phar entry is a directory, cannot set compression"); \ - return; + RETURN_THROWS(); } if ((entry_obj->entry->flags & PHAR_ENT_COMPRESSION_MASK) == 0) { @@ -5074,25 +5077,25 @@ PHP_METHOD(PharFileInfo, decompress) if (PHAR_G(readonly) && !entry_obj->entry->phar->is_data) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Phar is readonly, cannot decompress"); - return; + RETURN_THROWS(); } if (entry_obj->entry->is_deleted) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot compress deleted file"); - return; + RETURN_THROWS(); } if ((entry_obj->entry->flags & PHAR_ENT_COMPRESSED_GZ) != 0 && !PHAR_G(has_zlib)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot decompress Gzip-compressed file, zlib extension is not enabled"); - return; + RETURN_THROWS(); } if ((entry_obj->entry->flags & PHAR_ENT_COMPRESSED_BZ2) != 0 && !PHAR_G(has_bz2)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot decompress Bzip2-compressed file, bz2 extension is not enabled"); - return; + RETURN_THROWS(); } if (entry_obj->entry->is_persistent) { @@ -5100,7 +5103,7 @@ PHP_METHOD(PharFileInfo, decompress) if (FAILURE == phar_copy_on_write(&phar)) { zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar->fname); - return; + RETURN_THROWS(); } /* re-populate after copy-on-write */ entry_obj->entry = zend_hash_str_find_ptr(&phar->manifest, entry_obj->entry->filename, entry_obj->entry->filename_len); @@ -5108,7 +5111,7 @@ PHP_METHOD(PharFileInfo, decompress) if (!entry_obj->entry->fp) { if (FAILURE == phar_open_archive_fp(entry_obj->entry->phar)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot decompress entry \"%s\", phar error: Cannot open phar archive \"%s\" for reading", entry_obj->entry->filename, entry_obj->entry->phar->fname); - return; + RETURN_THROWS(); } entry_obj->entry->fp_type = PHAR_FP; } @@ -5122,7 +5125,9 @@ PHP_METHOD(PharFileInfo, decompress) if (error) { zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error); efree(error); + RETURN_THROWS(); } + RETURN_TRUE; } /* }}} */ diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index f7820ddb31..4e922e3ef0 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -2283,15 +2283,15 @@ SXE_METHOD(__construct) if (ZEND_SIZE_T_INT_OVFL(data_len)) { zend_throw_exception(zend_ce_exception, "Data is too long", 0); - return; + RETURN_THROWS(); } if (ZEND_SIZE_T_INT_OVFL(ns_len)) { zend_throw_exception(zend_ce_exception, "Namespace is too long", 0); - return; + RETURN_THROWS(); } if (ZEND_LONG_EXCEEDS_INT(options)) { zend_throw_exception(zend_ce_exception, "Invalid options", 0); - return; + RETURN_THROWS(); } docp = is_url ? xmlReadFile(data, NULL, (int)options) : xmlReadMemory(data, (int)data_len, NULL, NULL, (int)options); @@ -2299,7 +2299,7 @@ SXE_METHOD(__construct) if (!docp) { ((php_libxml_node_object *)sxe)->document = NULL; zend_throw_exception(zend_ce_exception, "String could not be parsed as XML", 0); - return; + RETURN_THROWS(); } sxe->iter.nsprefix = ns_len ? (xmlChar*)estrdup(ns) : NULL; diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 530cd80d75..0cf1061acf 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1541,7 +1541,7 @@ PHP_METHOD(snmp, __construct) break; default: zend_throw_exception(zend_ce_exception, "Unknown SNMP protocol version", 0); - return; + RETURN_THROWS(); } /* handle re-open of snmp session */ diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 0e7452d0b2..02a3537b27 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -500,7 +500,7 @@ PHP_FUNCTION(sodium_memzero) ZVAL_DEREF(buf_zv); if (Z_TYPE_P(buf_zv) != IS_STRING) { zend_throw_exception(sodium_exception_ce, "a PHP string is required", 0); - return; + RETURN_THROWS(); } if (Z_REFCOUNTED_P(buf_zv) && Z_REFCOUNT_P(buf_zv) == 1) { char *buf = Z_STRVAL(*buf_zv); @@ -526,7 +526,7 @@ PHP_FUNCTION(sodium_increment) ZVAL_DEREF(val_zv); if (Z_TYPE_P(val_zv) != IS_STRING) { zend_throw_exception(sodium_exception_ce, "a PHP string is required", 0); - return; + RETURN_THROWS(); } sodium_separate_string(val_zv); @@ -551,7 +551,7 @@ PHP_FUNCTION(sodium_add) ZVAL_DEREF(val_zv); if (Z_TYPE_P(val_zv) != IS_STRING) { zend_throw_exception(sodium_exception_ce, "PHP strings are required", 0); - return; + RETURN_THROWS(); } sodium_separate_string(val_zv); @@ -559,7 +559,7 @@ PHP_FUNCTION(sodium_add) val_len = Z_STRLEN(*val_zv); if (val_len != addv_len) { zend_throw_exception(sodium_exception_ce, "values must have the same length", 0); - return; + RETURN_THROWS(); } sodium_add(val, addv, val_len); } @@ -579,7 +579,7 @@ PHP_FUNCTION(sodium_memcmp) } if (len1 != len2) { zend_throw_exception(sodium_exception_ce, "arguments have different sizes", 0); - return; + RETURN_THROWS(); } RETURN_LONG(sodium_memcmp(buf1, buf2, len1)); } @@ -602,14 +602,14 @@ PHP_FUNCTION(sodium_crypto_shorthash) zend_throw_exception(sodium_exception_ce, "key size should be SODIUM_CRYPTO_SHORTHASH_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } hash = zend_string_alloc(crypto_shorthash_BYTES, 0); if (crypto_shorthash((unsigned char *) ZSTR_VAL(hash), msg, (unsigned long long) msg_len, key) != 0) { zend_string_efree(hash); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(hash)[crypto_shorthash_BYTES] = 0; @@ -637,17 +637,17 @@ PHP_FUNCTION(sodium_crypto_secretbox) zend_throw_exception(sodium_exception_ce, "nonce size should be SODIUM_CRYPTO_SECRETBOX_NONCEBYTES bytes", 0); - return; + RETURN_THROWS(); } if (key_len != crypto_secretbox_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "key size should be SODIUM_CRYPTO_SECRETBOX_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (SIZE_MAX - msg_len <= crypto_secretbox_MACBYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } ciphertext = zend_string_alloc((size_t) msg_len + crypto_secretbox_MACBYTES, 0); if (crypto_secretbox_easy((unsigned char *) ZSTR_VAL(ciphertext), @@ -655,7 +655,7 @@ PHP_FUNCTION(sodium_crypto_secretbox) nonce, key) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(ciphertext)[msg_len + crypto_secretbox_MACBYTES] = 0; @@ -683,13 +683,13 @@ PHP_FUNCTION(sodium_crypto_secretbox_open) zend_throw_exception(sodium_exception_ce, "nonce size should be SODIUM_CRYPTO_SECRETBOX_NONCEBYTES bytes", 0); - return; + RETURN_THROWS(); } if (key_len != crypto_secretbox_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "key size should be SODIUM_CRYPTO_SECRETBOX_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (ciphertext_len < crypto_secretbox_MACBYTES) { RETURN_FALSE; @@ -726,13 +726,13 @@ PHP_FUNCTION(sodium_crypto_generichash) if (hash_len < crypto_generichash_BYTES_MIN || hash_len > crypto_generichash_BYTES_MAX) { zend_throw_exception(sodium_exception_ce, "unsupported output length", 0); - return; + RETURN_THROWS(); } if (key_len != 0 && (key_len < crypto_generichash_KEYBYTES_MIN || key_len > crypto_generichash_KEYBYTES_MAX)) { zend_throw_exception(sodium_exception_ce, "unsupported key length", 0); - return; + RETURN_THROWS(); } hash = zend_string_alloc(hash_len, 0); if (crypto_generichash((unsigned char *) ZSTR_VAL(hash), (size_t) hash_len, @@ -740,7 +740,7 @@ PHP_FUNCTION(sodium_crypto_generichash) key, (size_t) key_len) != 0) { zend_string_efree(hash); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(hash)[hash_len] = 0; @@ -765,19 +765,19 @@ PHP_FUNCTION(sodium_crypto_generichash_init) if (hash_len < crypto_generichash_BYTES_MIN || hash_len > crypto_generichash_BYTES_MAX) { zend_throw_exception(sodium_exception_ce, "unsupported output length", 0); - return; + RETURN_THROWS(); } if (key_len != 0 && (key_len < crypto_generichash_KEYBYTES_MIN || key_len > crypto_generichash_KEYBYTES_MAX)) { zend_throw_exception(sodium_exception_ce, "unsupported key length", 0); - return; + RETURN_THROWS(); } memset(&state_tmp, 0, sizeof state_tmp); if (crypto_generichash_init((void *) &state_tmp, key, (size_t) key_len, (size_t) hash_len) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } state = zend_string_alloc(state_len, 0); memcpy(ZSTR_VAL(state), &state_tmp, state_len); @@ -804,21 +804,21 @@ PHP_FUNCTION(sodium_crypto_generichash_update) ZVAL_DEREF(state_zv); if (Z_TYPE_P(state_zv) != IS_STRING) { zend_throw_exception(sodium_exception_ce, "a reference to a state is required", 0); - return; + RETURN_THROWS(); } sodium_separate_string(state_zv); state = (unsigned char *) Z_STRVAL(*state_zv); state_len = Z_STRLEN(*state_zv); if (state_len != sizeof (crypto_generichash_state)) { zend_throw_exception(sodium_exception_ce, "incorrect state length", 0); - return; + RETURN_THROWS(); } memcpy(&state_tmp, state, sizeof state_tmp); if (crypto_generichash_update((void *) &state_tmp, msg, (unsigned long long) msg_len) != 0) { sodium_memzero(&state_tmp, sizeof state_tmp); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } memcpy(state, &state_tmp, state_len); sodium_memzero(&state_tmp, sizeof state_tmp); @@ -843,19 +843,19 @@ PHP_FUNCTION(sodium_crypto_generichash_final) ZVAL_DEREF(state_zv); if (Z_TYPE_P(state_zv) != IS_STRING) { zend_throw_exception(sodium_exception_ce, "a reference to a state is required", 0); - return; + RETURN_THROWS(); } sodium_separate_string(state_zv); state = (unsigned char *) Z_STRVAL(*state_zv); state_len = Z_STRLEN(*state_zv); if (state_len != sizeof (crypto_generichash_state)) { zend_throw_exception(sodium_exception_ce, "incorrect state length", 0); - return; + RETURN_THROWS(); } if (hash_len < crypto_generichash_BYTES_MIN || hash_len > crypto_generichash_BYTES_MAX) { zend_throw_exception(sodium_exception_ce, "unsupported output length", 0); - return; + RETURN_THROWS(); } hash = zend_string_alloc(hash_len, 0); memcpy(&state_tmp, state, sizeof state_tmp); @@ -865,7 +865,7 @@ PHP_FUNCTION(sodium_crypto_generichash_final) sodium_memzero(&state_tmp, sizeof state_tmp); zend_string_efree(hash); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } sodium_memzero(&state_tmp, sizeof state_tmp); sodium_memzero(state, state_len); @@ -890,7 +890,7 @@ PHP_FUNCTION(sodium_crypto_box_keypair) (unsigned char *) ZSTR_VAL(keypair)) != 0) { zend_string_efree(keypair); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(keypair)[keypair_len] = 0; @@ -913,7 +913,7 @@ PHP_FUNCTION(sodium_crypto_box_seed_keypair) zend_throw_exception(sodium_exception_ce, "seed should be SODIUM_CRYPTO_BOX_SEEDBYTES bytes", 0); - return; + RETURN_THROWS(); } keypair_len = crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES; keypair = zend_string_alloc(keypair_len, 0); @@ -923,7 +923,7 @@ PHP_FUNCTION(sodium_crypto_box_seed_keypair) seed) != 0) { zend_string_efree(keypair); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(keypair)[keypair_len] = 0; @@ -949,13 +949,13 @@ PHP_FUNCTION(sodium_crypto_box_keypair_from_secretkey_and_publickey) zend_throw_exception(sodium_exception_ce, "secretkey should be SODIUM_CRYPTO_BOX_SECRETKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (publickey_len != crypto_box_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "publickey should be SODIUM_CRYPTO_BOX_PUBLICKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } keypair_len = crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES; keypair = zend_string_alloc(keypair_len, 0); @@ -983,7 +983,7 @@ PHP_FUNCTION(sodium_crypto_box_secretkey) zend_throw_exception(sodium_exception_ce, "keypair should be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } secretkey = zend_string_alloc(crypto_box_SECRETKEYBYTES, 0); memcpy(ZSTR_VAL(secretkey), keypair, crypto_box_SECRETKEYBYTES); @@ -1008,7 +1008,7 @@ PHP_FUNCTION(sodium_crypto_box_publickey) zend_throw_exception(sodium_exception_ce, "keypair should be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } publickey = zend_string_alloc(crypto_box_PUBLICKEYBYTES, 0); memcpy(ZSTR_VAL(publickey), keypair + crypto_box_SECRETKEYBYTES, @@ -1033,7 +1033,7 @@ PHP_FUNCTION(sodium_crypto_box_publickey_from_secretkey) zend_throw_exception(sodium_exception_ce, "key should be SODIUM_CRYPTO_BOX_SECRETKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } publickey = zend_string_alloc(crypto_box_PUBLICKEYBYTES, 0); (void) sizeof(int[crypto_scalarmult_BYTES == @@ -1069,19 +1069,19 @@ PHP_FUNCTION(sodium_crypto_box) zend_throw_exception(sodium_exception_ce, "nonce size should be SODIUM_CRYPTO_BOX_NONCEBYTES bytes", 0); - return; + RETURN_THROWS(); } if (keypair_len != crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "keypair size should be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } secretkey = keypair; publickey = keypair + crypto_box_SECRETKEYBYTES; if (SIZE_MAX - msg_len <= crypto_box_MACBYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } ciphertext = zend_string_alloc((size_t) msg_len + crypto_box_MACBYTES, 0); if (crypto_box_easy((unsigned char *) ZSTR_VAL(ciphertext), msg, @@ -1089,7 +1089,7 @@ PHP_FUNCTION(sodium_crypto_box) nonce, publickey, secretkey) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(ciphertext)[msg_len + crypto_box_MACBYTES] = 0; @@ -1119,13 +1119,13 @@ PHP_FUNCTION(sodium_crypto_box_open) zend_throw_exception(sodium_exception_ce, "nonce size should be SODIUM_CRYPTO_BOX_NONCEBYTES bytes", 0); - return; + RETURN_THROWS(); } if (keypair_len != crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "keypair size should be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } secretkey = keypair; publickey = keypair + crypto_box_SECRETKEYBYTES; @@ -1162,18 +1162,18 @@ PHP_FUNCTION(sodium_crypto_box_seal) zend_throw_exception(sodium_exception_ce, "public key size should be SODIUM_CRYPTO_BOX_PUBLICKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (SIZE_MAX - msg_len <= crypto_box_SEALBYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } ciphertext = zend_string_alloc((size_t) msg_len + crypto_box_SEALBYTES, 0); if (crypto_box_seal((unsigned char *) ZSTR_VAL(ciphertext), msg, (unsigned long long) msg_len, publickey) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(ciphertext)[msg_len + crypto_box_SEALBYTES] = 0; @@ -1200,7 +1200,7 @@ PHP_FUNCTION(sodium_crypto_box_seal_open) zend_throw_exception(sodium_exception_ce, "keypair size should be SODIUM_CRYPTO_BOX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } secretkey = keypair; publickey = keypair + crypto_box_SECRETKEYBYTES; @@ -1234,7 +1234,7 @@ PHP_FUNCTION(sodium_crypto_sign_keypair) (unsigned char *) ZSTR_VAL(keypair)) != 0) { zend_string_efree(keypair); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(keypair)[keypair_len] = 0; @@ -1257,7 +1257,7 @@ PHP_FUNCTION(sodium_crypto_sign_seed_keypair) zend_throw_exception(sodium_exception_ce, "seed should be SODIUM_CRYPTO_SIGN_SEEDBYTES bytes", 0); - return; + RETURN_THROWS(); } keypair_len = crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES; keypair = zend_string_alloc(keypair_len, 0); @@ -1267,7 +1267,7 @@ PHP_FUNCTION(sodium_crypto_sign_seed_keypair) seed) != 0) { zend_string_efree(keypair); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(keypair)[keypair_len] = 0; @@ -1293,13 +1293,13 @@ PHP_FUNCTION(sodium_crypto_sign_keypair_from_secretkey_and_publickey) zend_throw_exception(sodium_exception_ce, "secretkey should be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (publickey_len != crypto_sign_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "publickey should be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } keypair_len = crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES; keypair = zend_string_alloc(keypair_len, 0); @@ -1326,7 +1326,7 @@ PHP_FUNCTION(sodium_crypto_sign_publickey_from_secretkey) zend_throw_exception(sodium_exception_ce, "secretkey should be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } publickey = zend_string_alloc(crypto_sign_PUBLICKEYBYTES, 0); @@ -1334,7 +1334,7 @@ PHP_FUNCTION(sodium_crypto_sign_publickey_from_secretkey) (const unsigned char *) secretkey) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(publickey)[crypto_sign_PUBLICKEYBYTES] = 0; @@ -1357,7 +1357,7 @@ PHP_FUNCTION(sodium_crypto_sign_secretkey) zend_throw_exception(sodium_exception_ce, "keypair should be SODIUM_CRYPTO_SIGN_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } secretkey = zend_string_alloc(crypto_sign_SECRETKEYBYTES, 0); memcpy(ZSTR_VAL(secretkey), keypair, crypto_sign_SECRETKEYBYTES); @@ -1382,7 +1382,7 @@ PHP_FUNCTION(sodium_crypto_sign_publickey) zend_throw_exception(sodium_exception_ce, "keypair should be SODIUM_CRYPTO_SIGN_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } publickey = zend_string_alloc(crypto_sign_PUBLICKEYBYTES, 0); memcpy(ZSTR_VAL(publickey), keypair + crypto_sign_SECRETKEYBYTES, @@ -1412,11 +1412,11 @@ PHP_FUNCTION(sodium_crypto_sign) zend_throw_exception(sodium_exception_ce, "secret key size should be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (SIZE_MAX - msg_len <= crypto_sign_BYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } msg_signed_len = msg_len + crypto_sign_BYTES; msg_signed = zend_string_alloc((size_t) msg_signed_len, 0); @@ -1425,12 +1425,12 @@ PHP_FUNCTION(sodium_crypto_sign) (unsigned long long) msg_len, secretkey) != 0) { zend_string_efree(msg_signed); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } if (msg_signed_real_len >= SIZE_MAX || msg_signed_real_len > msg_signed_len) { zend_string_efree(msg_signed); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(msg_signed, (size_t) msg_signed_real_len); ZSTR_VAL(msg_signed)[msg_signed_real_len] = 0; @@ -1458,12 +1458,12 @@ PHP_FUNCTION(sodium_crypto_sign_open) zend_throw_exception(sodium_exception_ce, "public key size should be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } msg_len = msg_signed_len; if (msg_len >= SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } msg = zend_string_alloc((size_t) msg_len, 0); if (crypto_sign_open((unsigned char *) ZSTR_VAL(msg), &msg_real_len, @@ -1475,7 +1475,7 @@ PHP_FUNCTION(sodium_crypto_sign_open) if (msg_real_len >= SIZE_MAX || msg_real_len > msg_signed_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len); ZSTR_VAL(msg)[msg_real_len] = 0; @@ -1502,7 +1502,7 @@ PHP_FUNCTION(sodium_crypto_sign_detached) zend_throw_exception(sodium_exception_ce, "secret key size should be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } signature = zend_string_alloc((size_t) crypto_sign_BYTES, 0); memset(ZSTR_VAL(signature), 0, (size_t) crypto_sign_BYTES); @@ -1511,12 +1511,12 @@ PHP_FUNCTION(sodium_crypto_sign_detached) (unsigned long long) msg_len, secretkey) != 0) { zend_string_efree(signature); zend_throw_exception(sodium_exception_ce, "signature creation failed", 0); - return; + RETURN_THROWS(); } if (signature_real_len <= 0U || signature_real_len > crypto_sign_BYTES) { zend_string_efree(signature); zend_throw_exception(sodium_exception_ce, "signature has a bogus size", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(signature, (size_t) signature_real_len); ZSTR_VAL(signature)[signature_real_len] = 0; @@ -1544,13 +1544,13 @@ PHP_FUNCTION(sodium_crypto_sign_verify_detached) zend_throw_exception(sodium_exception_ce, "signature size should be SODIUM_CRYPTO_SIGN_BYTES bytes", 0); - return; + RETURN_THROWS(); } if (publickey_len != crypto_sign_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "public key size should be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (crypto_sign_verify_detached(signature, msg, (unsigned long long) msg_len, @@ -1578,22 +1578,22 @@ PHP_FUNCTION(sodium_crypto_stream) } if (ciphertext_len <= 0 || ciphertext_len >= SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "ciphertext length must be greater than 0", 0); - return; + RETURN_THROWS(); } if (nonce_len != crypto_stream_NONCEBYTES) { zend_throw_exception(sodium_exception_ce, "nonce should be SODIUM_CRYPTO_STREAM_NONCEBYTES bytes", 0); - return; + RETURN_THROWS(); } if (key_len != crypto_stream_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "key should be SODIUM_CRYPTO_STREAM_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); if (crypto_stream((unsigned char *) ZSTR_VAL(ciphertext), (unsigned long long) ciphertext_len, nonce, key) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(ciphertext)[ciphertext_len] = 0; @@ -1620,11 +1620,11 @@ PHP_FUNCTION(sodium_crypto_stream_xor) } if (nonce_len != crypto_stream_NONCEBYTES) { zend_throw_exception(sodium_exception_ce, "nonce should be SODIUM_CRYPTO_STREAM_NONCEBYTES bytes", 0); - return; + RETURN_THROWS(); } if (key_len != crypto_stream_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "key should be SODIUM_CRYPTO_STREAM_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } ciphertext_len = msg_len; ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); @@ -1632,7 +1632,7 @@ PHP_FUNCTION(sodium_crypto_stream_xor) (unsigned long long) msg_len, nonce, key) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(ciphertext)[ciphertext_len] = 0; @@ -1664,19 +1664,19 @@ PHP_FUNCTION(sodium_crypto_pwhash) } if (hash_len <= 0 || hash_len >= 0xffffffff) { zend_throw_exception(sodium_exception_ce, "hash length must be greater than 0", 0); - return; + RETURN_THROWS(); } if (passwd_len >= 0xffffffff) { zend_throw_exception(sodium_exception_ce, "unsupported password length", 0); - return; + RETURN_THROWS(); } if (opslimit <= 0) { zend_throw_exception(sodium_exception_ce, "ops limit must be greater than 0", 0); - return; + RETURN_THROWS(); } if (memlimit <= 0 || memlimit > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "memory limit must be greater than 0", 0); - return; + RETURN_THROWS(); } if (alg != crypto_pwhash_ALG_ARGON2I13 # ifdef crypto_pwhash_ALG_ARGON2ID13 @@ -1684,19 +1684,19 @@ PHP_FUNCTION(sodium_crypto_pwhash) # endif && alg != crypto_pwhash_ALG_DEFAULT) { zend_throw_exception(sodium_exception_ce, "unsupported password hashing algorithm", 0); - return; + RETURN_THROWS(); } if (passwd_len <= 0) { zend_error(E_WARNING, "empty password"); } if (salt_len != crypto_pwhash_SALTBYTES) { zend_throw_exception(sodium_exception_ce, "salt should be SODIUM_CRYPTO_PWHASH_SALTBYTES bytes", 0); - return; + RETURN_THROWS(); } if (opslimit < crypto_pwhash_OPSLIMIT_MIN) { zend_throw_exception(sodium_exception_ce, "number of operations for the password hashing function is too low", 0); - return; + RETURN_THROWS(); } if (memlimit < crypto_pwhash_MEMLIMIT_MIN) { zend_throw_exception(sodium_exception_ce, @@ -1721,7 +1721,7 @@ PHP_FUNCTION(sodium_crypto_pwhash) if (ret != 0) { zend_string_efree(hash); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(hash)[hash_len] = 0; @@ -1745,15 +1745,15 @@ PHP_FUNCTION(sodium_crypto_pwhash_str) } if (opslimit <= 0) { zend_throw_exception(sodium_exception_ce, "ops limit must be greater than 0", 0); - return; + RETURN_THROWS(); } if (memlimit <= 0 || memlimit > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "memory limit must be greater than 0", 0); - return; + RETURN_THROWS(); } if (passwd_len >= 0xffffffff) { zend_throw_exception(sodium_exception_ce, "unsupported password length", 0); - return; + RETURN_THROWS(); } if (passwd_len <= 0) { zend_error(E_WARNING, "empty password"); @@ -1772,7 +1772,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_str) (unsigned long long) opslimit, (size_t) memlimit) != 0) { zend_string_efree(hash_str); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(hash_str)[crypto_pwhash_STRBYTES - 1] = 0; @@ -1818,7 +1818,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_str_verify) if (passwd_len >= 0xffffffff) { zend_throw_exception(sodium_exception_ce, "unsupported password length", 0); - return; + RETURN_THROWS(); } if (passwd_len <= 0) { zend_error(E_WARNING, "empty password"); @@ -1853,15 +1853,15 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256) } if (hash_len <= 0 || hash_len >= SIZE_MAX || hash_len > 0x1fffffffe0ULL) { zend_throw_exception(sodium_exception_ce, "hash length must be greater than 0", 0); - return; + RETURN_THROWS(); } if (opslimit <= 0) { zend_throw_exception(sodium_exception_ce, "ops limit must be greater than 0", 0); - return; + RETURN_THROWS(); } if (memlimit <= 0 || memlimit > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "memory limit must be greater than 0", 0); - return; + RETURN_THROWS(); } if (passwd_len <= 0) { zend_error(E_WARNING, "empty password"); @@ -1870,7 +1870,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256) zend_throw_exception(sodium_exception_ce, "salt should be SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES bytes", 0); - return; + RETURN_THROWS(); } if (opslimit < crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE) { zend_throw_exception(sodium_exception_ce, @@ -1887,7 +1887,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256) (unsigned long long) opslimit, (size_t) memlimit) != 0) { zend_string_efree(hash); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(hash)[hash_len] = 0; @@ -1910,11 +1910,11 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str) } if (opslimit <= 0) { zend_throw_exception(sodium_exception_ce, "ops limit must be greater than 0", 0); - return; + RETURN_THROWS(); } if (memlimit <= 0 || memlimit > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "memory limit must be greater than 0", 0); - return; + RETURN_THROWS(); } if (passwd_len <= 0) { zend_error(E_WARNING, "empty password"); @@ -1934,7 +1934,7 @@ PHP_FUNCTION(sodium_crypto_pwhash_scryptsalsa208sha256_str) (unsigned long long) opslimit, (size_t) memlimit) != 0) { zend_string_efree(hash_str); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(hash_str)[crypto_pwhash_scryptsalsa208sha256_STRBYTES - 1] = 0; @@ -2009,22 +2009,22 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt) "public nonce size should be " "SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES bytes", 0); - return; + RETURN_THROWS(); } if (secretkey_len != crypto_aead_aes256gcm_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "secret key size should be " "SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (SIZE_MAX - msg_len <= crypto_aead_aes256gcm_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } if ((unsigned long long) msg_len > (16ULL * ((1ULL << 32) - 2ULL)) - crypto_aead_aes256gcm_ABYTES) { zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0); - return; + RETURN_THROWS(); } ciphertext_len = msg_len + crypto_aead_aes256gcm_ABYTES; ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); @@ -2034,13 +2034,13 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_encrypt) ad, (unsigned long long) ad_len, NULL, npub, secretkey) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(ciphertext, (size_t) ciphertext_real_len); ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0; @@ -2075,26 +2075,26 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt) "public nonce size should be " "SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES bytes", 0); - return; + RETURN_THROWS(); } if (secretkey_len != crypto_aead_aes256gcm_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "secret key size should be " "SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (ciphertext_len < crypto_aead_aes256gcm_ABYTES) { RETURN_FALSE; } if (ciphertext_len - crypto_aead_aes256gcm_ABYTES > 16ULL * ((1ULL << 32) - 2ULL)) { zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0); - return; + RETURN_THROWS(); } msg_len = ciphertext_len; if (msg_len >= SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } msg = zend_string_alloc((size_t) msg_len, 0); if (crypto_aead_aes256gcm_decrypt @@ -2107,7 +2107,7 @@ PHP_FUNCTION(sodium_crypto_aead_aes256gcm_decrypt) if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len); ZSTR_VAL(msg)[msg_real_len] = 0; @@ -2143,18 +2143,18 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt) "public nonce size should be " "SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES bytes", 0); - return; + RETURN_THROWS(); } if (secretkey_len != crypto_aead_chacha20poly1305_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "secret key size should be " "SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (SIZE_MAX - msg_len <= crypto_aead_chacha20poly1305_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } ciphertext_len = msg_len + crypto_aead_chacha20poly1305_ABYTES; ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); @@ -2164,13 +2164,13 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_encrypt) ad, (unsigned long long) ad_len, NULL, npub, secretkey) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(ciphertext, (size_t) ciphertext_real_len); ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0; @@ -2205,14 +2205,14 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt) "public nonce size should be " "SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES bytes", 0); - return; + RETURN_THROWS(); } if (secretkey_len != crypto_aead_chacha20poly1305_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "secret key size should be " "SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (ciphertext_len < crypto_aead_chacha20poly1305_ABYTES) { RETURN_FALSE; @@ -2220,7 +2220,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt) msg_len = ciphertext_len; if (msg_len >= SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } msg = zend_string_alloc((size_t) msg_len, 0); if (crypto_aead_chacha20poly1305_decrypt @@ -2233,7 +2233,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_decrypt) if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len); ZSTR_VAL(msg)[msg_real_len] = 0; @@ -2268,22 +2268,22 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt) "public nonce size should be " "SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES bytes", 0); - return; + RETURN_THROWS(); } if (secretkey_len != crypto_aead_chacha20poly1305_IETF_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "secret key size should be " "SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (SIZE_MAX - msg_len <= crypto_aead_chacha20poly1305_IETF_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } if ((unsigned long long) msg_len > 64ULL * (1ULL << 32) - 64ULL) { zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0); - return; + RETURN_THROWS(); } ciphertext_len = msg_len + crypto_aead_chacha20poly1305_IETF_ABYTES; ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); @@ -2293,13 +2293,13 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_encrypt) ad, (unsigned long long) ad_len, NULL, npub, secretkey) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(ciphertext, (size_t) ciphertext_real_len); ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0; @@ -2334,19 +2334,19 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt) "public nonce size should be " "SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES bytes", 0); - return; + RETURN_THROWS(); } if (secretkey_len != crypto_aead_chacha20poly1305_IETF_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "secret key size should be " "SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } msg_len = ciphertext_len; if (msg_len >= SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } if (ciphertext_len < crypto_aead_chacha20poly1305_IETF_ABYTES) { RETURN_FALSE; @@ -2354,7 +2354,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt) if ((unsigned long long) ciphertext_len - crypto_aead_chacha20poly1305_IETF_ABYTES > 64ULL * (1ULL << 32) - 64ULL) { zend_throw_exception(sodium_exception_ce, "message too long for a single key", 0); - return; + RETURN_THROWS(); } msg = zend_string_alloc((size_t) msg_len, 0); if (crypto_aead_chacha20poly1305_ietf_decrypt @@ -2367,7 +2367,7 @@ PHP_FUNCTION(sodium_crypto_aead_chacha20poly1305_ietf_decrypt) if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len); ZSTR_VAL(msg)[msg_real_len] = 0; @@ -2403,18 +2403,18 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt) "public nonce size should be " "SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES bytes", 0); - return; + RETURN_THROWS(); } if (secretkey_len != crypto_aead_xchacha20poly1305_IETF_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "secret key size should be " "SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (SIZE_MAX - msg_len <= crypto_aead_xchacha20poly1305_IETF_ABYTES) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } ciphertext_len = msg_len + crypto_aead_xchacha20poly1305_IETF_ABYTES; ciphertext = zend_string_alloc((size_t) ciphertext_len, 0); @@ -2424,13 +2424,13 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_encrypt) ad, (unsigned long long) ad_len, NULL, npub, secretkey) != 0) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } if (ciphertext_real_len <= 0U || ciphertext_real_len >= SIZE_MAX || ciphertext_real_len > ciphertext_len) { zend_string_efree(ciphertext); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(ciphertext, (size_t) ciphertext_real_len); ZSTR_VAL(ciphertext)[ciphertext_real_len] = 0; @@ -2465,14 +2465,14 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt) "public nonce size should be " "SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES bytes", 0); - return; + RETURN_THROWS(); } if (secretkey_len != crypto_aead_xchacha20poly1305_IETF_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "secret key size should be " "SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (ciphertext_len < crypto_aead_xchacha20poly1305_IETF_ABYTES) { RETURN_FALSE; @@ -2480,12 +2480,12 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt) msg_len = ciphertext_len; if (msg_len - crypto_aead_xchacha20poly1305_IETF_ABYTES >= SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } if ((unsigned long long) ciphertext_len - crypto_aead_xchacha20poly1305_IETF_ABYTES > 64ULL * (1ULL << 32) - 64ULL) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } msg = zend_string_alloc((size_t) msg_len, 0); if (crypto_aead_xchacha20poly1305_ietf_decrypt @@ -2498,7 +2498,7 @@ PHP_FUNCTION(sodium_crypto_aead_xchacha20poly1305_ietf_decrypt) if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len); ZSTR_VAL(msg)[msg_real_len] = 0; @@ -2521,7 +2521,7 @@ PHP_FUNCTION(sodium_bin2hex) } if (bin_len >= SIZE_MAX / 2U) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } hex_len = bin_len * 2U; hex = zend_string_alloc((size_t) hex_len, 0); @@ -2555,12 +2555,12 @@ PHP_FUNCTION(sodium_hex2bin) end != hex + hex_len) { zend_string_efree(bin); zend_throw_exception(sodium_exception_ce, "invalid hex string", 0); - return; + RETURN_THROWS(); } if (bin_real_len >= SIZE_MAX || bin_real_len > bin_len) { zend_string_efree(bin); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(bin, (size_t) bin_real_len); ZSTR_VAL(bin)[bin_real_len] = 0; @@ -2585,11 +2585,11 @@ PHP_FUNCTION(sodium_bin2base64) if ((((unsigned int) variant) & ~ 0x6U) != 0x1U) { zend_throw_exception(sodium_exception_ce, "invalid base64 variant identifier", 0); - return; + RETURN_THROWS(); } if (bin_len >= SIZE_MAX / 4U * 3U - 3U - 1U) { zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } b64_len = sodium_base64_ENCODED_LEN(bin_len, variant); b64 = zend_string_alloc((size_t) b64_len - 1U, 0); @@ -2619,7 +2619,7 @@ PHP_FUNCTION(sodium_base642bin) if ((((unsigned int) variant) & ~ 0x6U) != 0x1U) { zend_throw_exception(sodium_exception_ce, "invalid base64 variant identifier", 0); - return; + RETURN_THROWS(); } bin_len = b64_len / 4U * 3U + 2U; bin = zend_string_alloc(bin_len, 0); @@ -2629,12 +2629,12 @@ PHP_FUNCTION(sodium_base642bin) end != b64 + b64_len) { zend_string_efree(bin); zend_throw_exception(sodium_exception_ce, "invalid base64 string", 0); - return; + RETURN_THROWS(); } if (bin_real_len >= SIZE_MAX || bin_real_len > bin_len) { zend_string_efree(bin); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(bin, (size_t) bin_real_len); ZSTR_VAL(bin)[bin_real_len] = 0; @@ -2661,13 +2661,13 @@ PHP_FUNCTION(sodium_crypto_scalarmult) zend_throw_exception(sodium_exception_ce, "scalar and point must be " "SODIUM_CRYPTO_SCALARMULT_SCALARBYTES bytes", 0); - return; + RETURN_THROWS(); } q = zend_string_alloc(crypto_scalarmult_BYTES, 0); if (crypto_scalarmult((unsigned char *) ZSTR_VAL(q), n, p) != 0) { zend_string_efree(q); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(q)[crypto_scalarmult_BYTES] = 0; @@ -2689,7 +2689,7 @@ PHP_FUNCTION(sodium_crypto_kx_seed_keypair) } if (seed_len != crypto_kx_SEEDBYTES) { zend_throw_exception(sodium_exception_ce, "seed must be SODIUM_CRYPTO_KX_SEEDBYTES bytes", 0); - return; + RETURN_THROWS(); } (void) sizeof(int[crypto_scalarmult_SCALARBYTES == crypto_kx_PUBLICKEYBYTES ? 1 : -1]); (void) sizeof(int[crypto_scalarmult_SCALARBYTES == crypto_kx_SECRETKEYBYTES ? 1 : -1]); @@ -2700,7 +2700,7 @@ PHP_FUNCTION(sodium_crypto_kx_seed_keypair) seed, crypto_kx_SEEDBYTES, NULL, 0); if (crypto_scalarmult_base(pk, sk) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(keypair)[crypto_kx_SECRETKEYBYTES + crypto_kx_PUBLICKEYBYTES] = 0; RETURN_STR(keypair); @@ -2721,7 +2721,7 @@ PHP_FUNCTION(sodium_crypto_kx_keypair) randombytes_buf(sk, crypto_kx_SECRETKEYBYTES); if (crypto_scalarmult_base(pk, sk) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } RETURN_STR(keypair); } @@ -2742,7 +2742,7 @@ PHP_FUNCTION(sodium_crypto_kx_secretkey) zend_throw_exception(sodium_exception_ce, "keypair should be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } secretkey = zend_string_alloc(crypto_kx_SECRETKEYBYTES, 0); memcpy(ZSTR_VAL(secretkey), keypair, crypto_kx_SECRETKEYBYTES); @@ -2767,7 +2767,7 @@ PHP_FUNCTION(sodium_crypto_kx_publickey) zend_throw_exception(sodium_exception_ce, "keypair should be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } publickey = zend_string_alloc(crypto_kx_PUBLICKEYBYTES, 0); memcpy(ZSTR_VAL(publickey), keypair + crypto_kx_SECRETKEYBYTES, @@ -2797,11 +2797,11 @@ PHP_FUNCTION(sodium_crypto_kx_client_session_keys) } if (keypair_len != crypto_kx_SECRETKEYBYTES + crypto_kx_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "keypair must be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } if (server_pk_len != crypto_kx_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "public keys must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } client_sk = &keypair[0]; client_pk = &keypair[crypto_kx_SECRETKEYBYTES]; @@ -2809,7 +2809,7 @@ PHP_FUNCTION(sodium_crypto_kx_client_session_keys) (void) sizeof(int[crypto_scalarmult_SCALARBYTES == crypto_kx_SECRETKEYBYTES ? 1 : -1]); if (crypto_scalarmult(q, client_sk, server_pk) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } crypto_generichash_init(&h, NULL, 0U, 2 * crypto_kx_SESSIONKEYBYTES); crypto_generichash_update(&h, q, sizeof q); @@ -2847,11 +2847,11 @@ PHP_FUNCTION(sodium_crypto_kx_server_session_keys) } if (keypair_len != crypto_kx_SECRETKEYBYTES + crypto_kx_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "keypair must be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes", 0); - return; + RETURN_THROWS(); } if (client_pk_len != crypto_kx_PUBLICKEYBYTES) { zend_throw_exception(sodium_exception_ce, "public keys must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } server_sk = &keypair[0]; server_pk = &keypair[crypto_kx_SECRETKEYBYTES]; @@ -2859,7 +2859,7 @@ PHP_FUNCTION(sodium_crypto_kx_server_session_keys) (void) sizeof(int[crypto_scalarmult_SCALARBYTES == crypto_kx_SECRETKEYBYTES ? 1 : -1]); if (crypto_scalarmult(q, server_sk, client_pk) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } crypto_generichash_init(&h, NULL, 0U, 2 * crypto_kx_SESSIONKEYBYTES); crypto_generichash_update(&h, q, sizeof q); @@ -2893,14 +2893,14 @@ PHP_FUNCTION(sodium_crypto_auth) } if (key_len != crypto_auth_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "key must be SODIUM_CRYPTO_AUTH_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } mac = zend_string_alloc(crypto_auth_BYTES, 0); if (crypto_auth((unsigned char *) ZSTR_VAL(mac), (const unsigned char *) msg, msg_len, (const unsigned char *) key) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(mac)[crypto_auth_BYTES] = 0; @@ -2925,11 +2925,11 @@ PHP_FUNCTION(sodium_crypto_auth_verify) } if (key_len != crypto_auth_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "key must be SODIUM_CRYPTO_AUTH_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (mac_len != crypto_auth_BYTES) { zend_throw_exception(sodium_exception_ce, "authentication tag must be SODIUM_CRYPTO_AUTH_BYTES bytes", 0); - return; + RETURN_THROWS(); } if (crypto_auth_verify((const unsigned char *) mac, (const unsigned char *) msg, msg_len, @@ -2954,14 +2954,14 @@ PHP_FUNCTION(sodium_crypto_sign_ed25519_sk_to_curve25519) zend_throw_exception(sodium_exception_ce, "Ed25519 key should be SODIUM_CRYPTO_SIGN_SECRETKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } ecdhkey = zend_string_alloc(crypto_box_SECRETKEYBYTES, 0); if (crypto_sign_ed25519_sk_to_curve25519((unsigned char *) ZSTR_VAL(ecdhkey), (const unsigned char *) eddsakey) != 0) { zend_throw_exception(sodium_exception_ce, "conversion failed", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(ecdhkey)[crypto_box_SECRETKEYBYTES] = 0; @@ -2983,14 +2983,14 @@ PHP_FUNCTION(sodium_crypto_sign_ed25519_pk_to_curve25519) zend_throw_exception(sodium_exception_ce, "Ed25519 key should be SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES bytes", 0); - return; + RETURN_THROWS(); } ecdhkey = zend_string_alloc(crypto_sign_PUBLICKEYBYTES, 0); if (crypto_sign_ed25519_pk_to_curve25519((unsigned char *) ZSTR_VAL(ecdhkey), (const unsigned char *) eddsakey) != 0) { zend_throw_exception(sodium_exception_ce, "conversion failed", 0); - return; + RETURN_THROWS(); } ZSTR_VAL(ecdhkey)[crypto_box_PUBLICKEYBYTES] = 0; @@ -3012,7 +3012,7 @@ PHP_FUNCTION(sodium_compare) } if (len1 != len2) { zend_throw_exception(sodium_exception_ce, "arguments have different sizes", 0); - return; + RETURN_THROWS(); } else { RETURN_LONG(sodium_compare((const unsigned char *) buf1, (const unsigned char *) buf2, (size_t) len1)); @@ -3157,23 +3157,23 @@ PHP_FUNCTION(sodium_crypto_kdf_derive_from_key) } if (subkey_len < crypto_kdf_BYTES_MIN) { zend_throw_exception(sodium_exception_ce, "subkey cannot be smaller than SODIUM_CRYPTO_KDF_BYTES_MIN", 0); - return; + RETURN_THROWS(); } if (subkey_len > crypto_kdf_BYTES_MAX || subkey_len > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "subkey cannot be larger than SODIUM_CRYPTO_KDF_BYTES_MAX", 0); - return; + RETURN_THROWS(); } if (subkey_id < 0) { zend_throw_exception(sodium_exception_ce, "subkey_id cannot be negative", 0); - return; + RETURN_THROWS(); } if (ctx_len != crypto_kdf_CONTEXTBYTES) { zend_throw_exception(sodium_exception_ce, "context should be SODIUM_CRYPTO_KDF_CONTEXTBYTES bytes", 0); - return; + RETURN_THROWS(); } if (key_len != crypto_kdf_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "key should be SODIUM_CRYPTO_KDF_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } memcpy(ctx_padded, ctx, crypto_kdf_CONTEXTBYTES); memset(ctx_padded + crypto_kdf_CONTEXTBYTES, 0, sizeof ctx_padded - crypto_kdf_CONTEXTBYTES); @@ -3222,11 +3222,11 @@ PHP_FUNCTION(sodium_pad) } if (blocksize <= 0) { zend_throw_exception(sodium_exception_ce, "block size cannot be less than 1", 0); - return; + RETURN_THROWS(); } if (blocksize > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "block size is too large", 0); - return; + RETURN_THROWS(); } xpadlen = blocksize - 1U; if ((blocksize & (blocksize - 1U)) == 0U) { @@ -3236,7 +3236,7 @@ PHP_FUNCTION(sodium_pad) } if ((size_t) SIZE_MAX - unpadded_len <= xpadlen) { zend_throw_exception(sodium_exception_ce, "input is too large", 0); - return; + RETURN_THROWS(); } xpadded_len = unpadded_len + xpadlen; padded = zend_string_alloc(xpadded_len + 1U, 0); @@ -3256,7 +3256,7 @@ PHP_FUNCTION(sodium_pad) if (sodium_pad(NULL, (unsigned char *) ZSTR_VAL(padded), unpadded_len, (size_t) blocksize, xpadded_len + 1U) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } #else { @@ -3295,15 +3295,15 @@ PHP_FUNCTION(sodium_unpad) } if (blocksize <= 0) { zend_throw_exception(sodium_exception_ce, "block size cannot be less than 1", 0); - return; + RETURN_THROWS(); } if (blocksize > SIZE_MAX) { zend_throw_exception(sodium_exception_ce, "block size is too large", 0); - return; + RETURN_THROWS(); } if (padded_len < blocksize) { zend_throw_exception(sodium_exception_ce, "invalid padding", 0); - return; + RETURN_THROWS(); } #if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) @@ -3335,7 +3335,7 @@ PHP_FUNCTION(sodium_unpad) #endif if (ret != 0 || unpadded_len > LONG_MAX) { zend_throw_exception(sodium_exception_ce, "invalid padding", 0); - return; + RETURN_THROWS(); } unpadded = zend_string_init(padded, padded_len, 0); PHP_SODIUM_ZSTR_TRUNCATE(unpadded, unpadded_len); @@ -3371,12 +3371,12 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_init_push) zend_throw_exception(sodium_exception_ce, "key size should be SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (crypto_secretstream_xchacha20poly1305_init_push(&state, header, key) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } array_init(return_value); add_next_index_stringl(return_value, (const char *) &state, sizeof state); @@ -3406,23 +3406,23 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push) ZVAL_DEREF(state_zv); if (Z_TYPE_P(state_zv) != IS_STRING) { zend_throw_exception(sodium_exception_ce, "a reference to a state is required", 0); - return; + RETURN_THROWS(); } sodium_separate_string(state_zv); state = (unsigned char *) Z_STRVAL(*state_zv); state_len = Z_STRLEN(*state_zv); if (state_len != sizeof (crypto_secretstream_xchacha20poly1305_state)) { zend_throw_exception(sodium_exception_ce, "incorrect state length", 0); - return; + RETURN_THROWS(); } if (msg_len > crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX || msg_len > SIZE_MAX - crypto_secretstream_xchacha20poly1305_ABYTES) { zend_throw_exception(sodium_exception_ce, "message cannot be larger than SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_MESSAGEBYTES_MAX bytes", 0); - return; + RETURN_THROWS(); } if (tag < 0 || tag > 255) { zend_throw_exception(sodium_exception_ce, "unsupported value for the tag", 0); - return; + RETURN_THROWS(); } c_len = msg_len + crypto_secretstream_xchacha20poly1305_ABYTES; c = zend_string_alloc((size_t) c_len, 0); @@ -3432,12 +3432,12 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_push) (unsigned char) tag) != 0) { zend_string_efree(c); zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } if (c_real_len <= 0U || c_real_len >= SIZE_MAX || c_real_len > c_len) { zend_string_efree(c); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(c, (size_t) c_real_len); ZSTR_VAL(c)[c_real_len] = 0; @@ -3463,18 +3463,18 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_init_pull) zend_throw_exception(sodium_exception_ce, "header size should be SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_HEADERBYTES bytes", 0); - return; + RETURN_THROWS(); } if (key_len != crypto_secretstream_xchacha20poly1305_KEYBYTES) { zend_throw_exception(sodium_exception_ce, "key size should be SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES bytes", 0); - return; + RETURN_THROWS(); } if (crypto_secretstream_xchacha20poly1305_init_pull(&state, header, key) != 0) { zend_throw_exception(sodium_exception_ce, "internal error", 0); - return; + RETURN_THROWS(); } RETURN_STRINGL((const char *) &state, sizeof state); } @@ -3502,14 +3502,14 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_pull) ZVAL_DEREF(state_zv); if (Z_TYPE_P(state_zv) != IS_STRING) { zend_throw_exception(sodium_exception_ce, "a reference to a state is required", 0); - return; + RETURN_THROWS(); } sodium_separate_string(state_zv); state = (unsigned char *) Z_STRVAL(*state_zv); state_len = Z_STRLEN(*state_zv); if (state_len != sizeof (crypto_secretstream_xchacha20poly1305_state)) { zend_throw_exception(sodium_exception_ce, "incorrect state length", 0); - return; + RETURN_THROWS(); } if (c_len < crypto_secretstream_xchacha20poly1305_ABYTES) { RETURN_FALSE; @@ -3525,7 +3525,7 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_pull) if (msg_real_len >= SIZE_MAX || msg_real_len > msg_len) { zend_string_efree(msg); zend_throw_exception(sodium_exception_ce, "arithmetic overflow", 0); - return; + RETURN_THROWS(); } PHP_SODIUM_ZSTR_TRUNCATE(msg, (size_t) msg_real_len); ZSTR_VAL(msg)[msg_real_len] = 0; @@ -3547,14 +3547,14 @@ PHP_FUNCTION(sodium_crypto_secretstream_xchacha20poly1305_rekey) ZVAL_DEREF(state_zv); if (Z_TYPE_P(state_zv) != IS_STRING) { zend_throw_exception(sodium_exception_ce, "a reference to a state is required", 0); - return; + RETURN_THROWS(); } sodium_separate_string(state_zv); state = (unsigned char *) Z_STRVAL(*state_zv); state_len = Z_STRLEN(*state_zv); if (state_len != sizeof (crypto_secretstream_xchacha20poly1305_state)) { zend_throw_exception(sodium_exception_ce, "incorrect state length", 0); - return; + RETURN_THROWS(); } crypto_secretstream_xchacha20poly1305_rekey((void *) state); } diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 0fb5cdcbe6..b9fdbd97c9 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1819,7 +1819,7 @@ SPL_METHOD(Array, unserialize) outexcept: PHP_VAR_UNSERIALIZE_DESTROY(var_hash); zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Error at offset " ZEND_LONG_FMT " of %zd bytes", (zend_long)((char*)p - buf), buf_len); - return; + RETURN_THROWS(); } /* }}} */ @@ -1874,7 +1874,7 @@ SPL_METHOD(Array, __unserialize) Z_TYPE_P(flags_zv) != IS_LONG || Z_TYPE_P(members_zv) != IS_ARRAY) { zend_throw_exception(spl_ce_UnexpectedValueException, "Incomplete or ill-typed serialization data", 0); - return; + RETURN_THROWS(); } flags = Z_LVAL_P(flags_zv); diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c index ffd3bf94f1..da61c41f0e 100644 --- a/ext/spl/spl_directory.c +++ b/ext/spl/spl_directory.c @@ -853,7 +853,7 @@ SPL_METHOD(DirectoryIterator, seek) zval_ptr_dtor(&retval); if (!valid) { zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0, "Seek position " ZEND_LONG_FMT " is out of range", pos); - return; + RETURN_THROWS(); } zend_call_method_with_0_params(Z_OBJ_P(ZEND_THIS), Z_OBJCE_P(ZEND_THIS), &intern->u.dir.func_next, "next", NULL); } @@ -2357,7 +2357,7 @@ SPL_METHOD(SplFileObject, eof) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } RETURN_BOOL(php_stream_eof(intern->u.file.stream)); @@ -2395,7 +2395,7 @@ SPL_METHOD(SplFileObject, fgets) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } if (spl_filesystem_file_read(intern, 0) == FAILURE) { @@ -2416,7 +2416,7 @@ SPL_METHOD(SplFileObject, current) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } if (!intern->u.file.current_line && Z_ISUNDEF(intern->u.file.current_zval)) { @@ -2505,7 +2505,7 @@ SPL_METHOD(SplFileObject, setMaxLineLen) if (max_len < 0) { zend_throw_exception_ex(spl_ce_DomainException, 0, "Maximum line length must be greater than or equal zero"); - return; + RETURN_THROWS(); } intern->u.file.max_line_len = max_len; @@ -2568,7 +2568,7 @@ SPL_METHOD(SplFileObject, fgetcsv) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } switch(ZEND_NUM_ARGS()) @@ -2750,7 +2750,7 @@ SPL_METHOD(SplFileObject, fflush) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } RETURN_BOOL(!php_stream_flush(intern->u.file.stream)); @@ -2765,7 +2765,7 @@ SPL_METHOD(SplFileObject, ftell) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } ret = php_stream_tell(intern->u.file.stream); @@ -2790,7 +2790,7 @@ SPL_METHOD(SplFileObject, fseek) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } spl_filesystem_file_free_line(intern); @@ -2807,7 +2807,7 @@ SPL_METHOD(SplFileObject, fgetc) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } spl_filesystem_file_free_line(intern); @@ -2835,7 +2835,7 @@ SPL_METHOD(SplFileObject, fpassthru) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } RETURN_LONG(php_stream_passthru(intern->u.file.stream)); @@ -2849,7 +2849,7 @@ SPL_METHOD(SplFileObject, fscanf) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } spl_filesystem_file_free_line(intern); @@ -2875,7 +2875,7 @@ SPL_METHOD(SplFileObject, fwrite) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } if (ZEND_NUM_ARGS() > 1) { @@ -2909,7 +2909,7 @@ SPL_METHOD(SplFileObject, fread) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } if (length <= 0) { @@ -2942,12 +2942,12 @@ SPL_METHOD(SplFileObject, ftruncate) if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } if (!php_stream_truncate_supported(intern->u.file.stream)) { zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't truncate file %s", intern->file_name); - RETURN_FALSE; + RETURN_THROWS(); } RETURN_BOOL(0 == php_stream_truncate_set_size(intern->u.file.stream, size)); @@ -2965,12 +2965,12 @@ SPL_METHOD(SplFileObject, seek) } if(!intern->u.file.stream) { zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Object not initialized"); - return; + RETURN_THROWS(); } if (line_pos < 0) { zend_throw_exception_ex(spl_ce_LogicException, 0, "Can't seek file %s to negative line " ZEND_LONG_FMT, intern->file_name, line_pos); - RETURN_FALSE; + RETURN_THROWS(); } spl_filesystem_file_rewind(ZEND_THIS, intern); diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c index fa37015c61..a9c7a3f939 100644 --- a/ext/spl/spl_dllist.c +++ b/ext/spl/spl_dllist.c @@ -601,7 +601,7 @@ SPL_METHOD(SplDoublyLinkedList, pop) if (Z_ISUNDEF_P(return_value)) { zend_throw_exception(spl_ce_RuntimeException, "Can't pop from an empty datastructure", 0); - RETURN_NULL(); + RETURN_THROWS(); } } /* }}} */ @@ -621,7 +621,7 @@ SPL_METHOD(SplDoublyLinkedList, shift) if (Z_ISUNDEF_P(return_value)) { zend_throw_exception(spl_ce_RuntimeException, "Can't shift from an empty datastructure", 0); - RETURN_NULL(); + RETURN_THROWS(); } } /* }}} */ @@ -642,7 +642,7 @@ SPL_METHOD(SplDoublyLinkedList, top) if (value == NULL || Z_ISUNDEF_P(value)) { zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty datastructure", 0); - return; + RETURN_THROWS(); } ZVAL_COPY_DEREF(return_value, value); @@ -665,7 +665,7 @@ SPL_METHOD(SplDoublyLinkedList, bottom) if (value == NULL || Z_ISUNDEF_P(value)) { zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty datastructure", 0); - return; + RETURN_THROWS(); } ZVAL_COPY_DEREF(return_value, value); @@ -719,7 +719,7 @@ SPL_METHOD(SplDoublyLinkedList, setIteratorMode) if (intern->flags & SPL_DLLIST_IT_FIX && (intern->flags & SPL_DLLIST_IT_LIFO) != (value & SPL_DLLIST_IT_LIFO)) { zend_throw_exception(spl_ce_RuntimeException, "Iterators' LIFO/FIFO modes for SplStack/SplQueue objects are frozen", 0); - return; + RETURN_THROWS(); } intern->flags = (value & SPL_DLLIST_IT_MASK) | (intern->flags & SPL_DLLIST_IT_FIX); @@ -780,7 +780,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetGet) if (index < 0 || index >= intern->llist->count) { zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0); - return; + RETURN_THROWS(); } element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO); @@ -819,7 +819,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet) if (index < 0 || index >= intern->llist->count) { zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0); - return; + RETURN_THROWS(); } element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO); @@ -842,7 +842,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetSet) } else { zval_ptr_dtor(value); zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0); - return; + RETURN_THROWS(); } } } /* }}} */ @@ -867,7 +867,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset) if (index < 0 || index >= intern->llist->count) { zend_throw_exception(spl_ce_OutOfRangeException, "Offset out of range", 0); - return; + RETURN_THROWS(); } element = spl_ptr_llist_offset(intern->llist, index, intern->flags & SPL_DLLIST_IT_LIFO); @@ -908,7 +908,7 @@ SPL_METHOD(SplDoublyLinkedList, offsetUnset) SPL_LLIST_DELREF(element); } else { zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid", 0); - return; + RETURN_THROWS(); } } /* }}} */ @@ -1210,7 +1210,7 @@ SPL_METHOD(SplDoublyLinkedList, unserialize) error: PHP_VAR_UNSERIALIZE_DESTROY(var_hash); zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Error at offset %zd of %zd bytes", ((char*)p - buf), buf_len); - return; + RETURN_THROWS(); } /* }}} */ @@ -1264,7 +1264,7 @@ SPL_METHOD(SplDoublyLinkedList, __unserialize) { Z_TYPE_P(members_zv) != IS_ARRAY) { zend_throw_exception(spl_ce_UnexpectedValueException, "Incomplete or ill-typed serialization data", 0); - return; + RETURN_THROWS(); } intern->flags = (int) Z_LVAL_P(flags_zv); @@ -1294,7 +1294,7 @@ SPL_METHOD(SplDoublyLinkedList, add) if (index < 0 || index > intern->llist->count) { zend_throw_exception(spl_ce_OutOfRangeException, "Offset invalid or out of range", 0); - return; + RETURN_THROWS(); } Z_TRY_ADDREF_P(value); diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 2c93c15864..0ac8d124f3 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -551,7 +551,7 @@ SPL_METHOD(SplFixedArray, __construct) if (size < 0) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array size cannot be less than zero"); - return; + RETURN_THROWS(); } intern = Z_SPLFIXEDARRAY_P(object); @@ -666,7 +666,7 @@ SPL_METHOD(SplFixedArray, fromArray) ZEND_HASH_FOREACH_KEY(Z_ARRVAL_P(data), num_index, str_index) { if (str_index != NULL || (zend_long)num_index < 0) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array must contain only positive integer keys"); - return; + RETURN_THROWS(); } if (num_index > max_index) { @@ -677,7 +677,7 @@ SPL_METHOD(SplFixedArray, fromArray) tmp = max_index + 1; if (tmp <= 0) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "integer overflow detected"); - return; + RETURN_THROWS(); } spl_fixedarray_init(&array, tmp); @@ -736,7 +736,7 @@ SPL_METHOD(SplFixedArray, setSize) if (size < 0) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "array size cannot be less than zero"); - return; + RETURN_THROWS(); } intern = Z_SPLFIXEDARRAY_P(object); diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index d43d8c5603..d7df5bd5e5 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -616,7 +616,7 @@ SPL_METHOD(SplHeap, insert) if (intern->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); - return; + RETURN_THROWS(); } Z_TRY_ADDREF_P(value); @@ -640,12 +640,12 @@ SPL_METHOD(SplHeap, extract) if (intern->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); - return; + RETURN_THROWS(); } if (spl_ptr_heap_delete_top(intern->heap, return_value, ZEND_THIS) == FAILURE) { zend_throw_exception(spl_ce_RuntimeException, "Can't extract from an empty heap", 0); - return; + RETURN_THROWS(); } } /* }}} */ @@ -666,7 +666,7 @@ SPL_METHOD(SplPriorityQueue, insert) if (intern->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); - return; + RETURN_THROWS(); } ZVAL_COPY(&elem.data, data); @@ -693,12 +693,12 @@ SPL_METHOD(SplPriorityQueue, extract) if (intern->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); - return; + RETURN_THROWS(); } if (spl_ptr_heap_delete_top(intern->heap, &elem, ZEND_THIS) == FAILURE) { zend_throw_exception(spl_ce_RuntimeException, "Can't extract from an empty heap", 0); - return; + RETURN_THROWS(); } spl_pqueue_extract_helper(return_value, &elem, intern->flags); @@ -721,14 +721,14 @@ SPL_METHOD(SplPriorityQueue, top) if (intern->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); - return; + RETURN_THROWS(); } elem = spl_ptr_heap_top(intern->heap); if (!elem) { zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty heap", 0); - return; + RETURN_THROWS(); } spl_pqueue_extract_helper(return_value, elem, intern->flags); @@ -750,7 +750,7 @@ SPL_METHOD(SplPriorityQueue, setExtractFlags) value &= SPL_PQUEUE_EXTR_MASK; if (!value) { zend_throw_exception(spl_ce_RuntimeException, "Must specify at least one extract flag", 0); - return; + RETURN_THROWS(); } intern = Z_SPLHEAP_P(ZEND_THIS); @@ -838,14 +838,14 @@ SPL_METHOD(SplHeap, top) if (intern->heap->flags & SPL_HEAP_CORRUPTED) { zend_throw_exception(spl_ce_RuntimeException, "Heap is corrupted, heap properties are no longer ensured.", 0); - return; + RETURN_THROWS(); } value = spl_ptr_heap_top(intern->heap); if (!value) { zend_throw_exception(spl_ce_RuntimeException, "Can't peek at an empty heap", 0); - return; + RETURN_THROWS(); } ZVAL_COPY_DEREF(return_value, value); diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 255f674aab..51a94ac5a4 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -135,7 +135,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob if (it->dit_type == DIT_Unknown) { \ zend_throw_exception_ex(spl_ce_LogicException, 0, \ "The object is in an invalid state as the parent constructor was not called"); \ - return; \ + RETURN_THROWS(); \ } \ (var) = it; \ } while (0) @@ -155,7 +155,7 @@ static inline spl_recursive_it_object *spl_recursive_it_from_obj(zend_object *ob if(!(object)->iterators) { \ zend_throw_exception_ex(spl_ce_LogicException, 0, \ "The object is in an invalid state as the parent constructor was not called"); \ - return; \ + RETURN_THROWS(); \ } \ (var) = &(object)->iterators[(object)->level].element; \ } while (0) @@ -717,7 +717,7 @@ SPL_METHOD(RecursiveIteratorIterator, getSubIterator) if(!object->iterators) { zend_throw_exception_ex(spl_ce_LogicException, 0, "The object is in an invalid state as the parent constructor was not called"); - return; + RETURN_THROWS(); } value = &object->iterators[level].zobject; @@ -856,7 +856,7 @@ SPL_METHOD(RecursiveIteratorIterator, setMaxDepth) } if (max_depth < -1) { zend_throw_exception(spl_ce_OutOfRangeException, "Parameter max_depth must be >= -1", 0); - return; + RETURN_THROWS(); } else if (max_depth > INT_MAX) { max_depth = INT_MAX; } @@ -1106,7 +1106,7 @@ SPL_METHOD(RecursiveTreeIterator, setPrefixPart) if (0 > part || part > 5) { zend_throw_exception_ex(spl_ce_OutOfRangeException, 0, "Use RecursiveTreeIterator::PREFIX_* constant"); - return; + RETURN_THROWS(); } smart_str_free(&object->prefix[part]); @@ -1126,7 +1126,7 @@ SPL_METHOD(RecursiveTreeIterator, getPrefix) if(!object->iterators) { zend_throw_exception_ex(spl_ce_LogicException, 0, "The object is in an invalid state as the parent constructor was not called"); - return; + RETURN_THROWS(); } spl_recursive_tree_iterator_get_prefix(object, return_value); @@ -1161,7 +1161,7 @@ SPL_METHOD(RecursiveTreeIterator, getEntry) if(!object->iterators) { zend_throw_exception_ex(spl_ce_LogicException, 0, "The object is in an invalid state as the parent constructor was not called"); - return; + RETURN_THROWS(); } spl_recursive_tree_iterator_get_entry(object, return_value); @@ -1180,7 +1180,7 @@ SPL_METHOD(RecursiveTreeIterator, getPostfix) if(!object->iterators) { zend_throw_exception_ex(spl_ce_LogicException, 0, "The object is in an invalid state as the parent constructor was not called"); - return; + RETURN_THROWS(); } spl_recursive_tree_iterator_get_postfix(object, return_value); @@ -1202,7 +1202,7 @@ SPL_METHOD(RecursiveTreeIterator, current) if(!object->iterators) { zend_throw_exception_ex(spl_ce_LogicException, 0, "The object is in an invalid state as the parent constructor was not called"); - return; + RETURN_THROWS(); } if (object->flags & RTIT_BYPASS_CURRENT) { @@ -1365,7 +1365,7 @@ static zend_function *spl_dual_it_get_method(zend_object **object, zend_string * if (intern->dit_type == DIT_Unknown) { \ zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Classes derived from %s must call %s::__construct()", \ ZSTR_VAL((spl_ce_##classname)->name), ZSTR_VAL((spl_ce_##classname)->name)); \ - return; \ + RETURN_THROWS(); \ } #define APPENDIT_CHECK_CTOR(intern) SPL_CHECK_CTOR(intern, AppendIterator) @@ -2087,7 +2087,7 @@ SPL_METHOD(RegexIterator, setMode) if (mode < 0 || mode >= REGIT_MODE_MAX) { zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, "Illegal mode " ZEND_LONG_FMT, mode); - return;/* NULL */ + RETURN_THROWS(); } SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS); @@ -2718,7 +2718,7 @@ SPL_METHOD(CachingIterator, __toString) if (!(intern->u.caching.flags & (CIT_CALL_TOSTRING|CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT|CIT_TOSTRING_USE_INNER))) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not fetch string value (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); - return; + RETURN_THROWS(); } if (intern->u.caching.flags & CIT_TOSTRING_USE_KEY) { ZVAL_COPY(return_value, &intern->current.key); @@ -2748,7 +2748,7 @@ SPL_METHOD(CachingIterator, offsetSet) if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "Sz", &key, &value) == FAILURE) { @@ -2772,7 +2772,7 @@ SPL_METHOD(CachingIterator, offsetGet) if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &key) == FAILURE) { @@ -2799,7 +2799,7 @@ SPL_METHOD(CachingIterator, offsetUnset) if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &key) == FAILURE) { @@ -2821,7 +2821,7 @@ SPL_METHOD(CachingIterator, offsetExists) if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &key) == FAILURE) { @@ -2846,7 +2846,7 @@ SPL_METHOD(CachingIterator, getCache) if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); - return; + RETURN_THROWS(); } ZVAL_COPY(return_value, &intern->u.caching.zcache); @@ -2884,15 +2884,15 @@ SPL_METHOD(CachingIterator, setFlags) if (spl_cit_check_flags(flags) != SUCCESS) { zend_throw_exception(spl_ce_InvalidArgumentException , "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0); - return; + RETURN_THROWS(); } if ((intern->u.caching.flags & CIT_CALL_TOSTRING) != 0 && (flags & CIT_CALL_TOSTRING) == 0) { zend_throw_exception(spl_ce_InvalidArgumentException, "Unsetting flag CALL_TO_STRING is not possible", 0); - return; + RETURN_THROWS(); } if ((intern->u.caching.flags & CIT_TOSTRING_USE_INNER) != 0 && (flags & CIT_TOSTRING_USE_INNER) == 0) { zend_throw_exception(spl_ce_InvalidArgumentException, "Unsetting flag TOSTRING_USE_INNER is not possible", 0); - return; + RETURN_THROWS(); } if ((flags & CIT_FULL_CACHE) != 0 && (intern->u.caching.flags & CIT_FULL_CACHE) == 0) { /* clear on (re)enable */ @@ -2916,7 +2916,7 @@ SPL_METHOD(CachingIterator, count) if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "%s does not use a full cache (see CachingIterator::__construct)", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); - return; + RETURN_THROWS(); } RETURN_LONG(zend_hash_num_elements(Z_ARRVAL(intern->u.caching.zcache))); diff --git a/ext/spl/spl_observer.c b/ext/spl/spl_observer.c index 256c592387..06b57cb68d 100644 --- a/ext/spl/spl_observer.c +++ b/ext/spl/spl_observer.c @@ -866,7 +866,7 @@ SPL_METHOD(SplObjectStorage, unserialize) outexcept: PHP_VAR_UNSERIALIZE_DESTROY(var_hash); zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Error at offset %zd of %zd bytes", ((char*)p - buf), buf_len); - return; + RETURN_THROWS(); } /* }}} */ @@ -916,12 +916,12 @@ SPL_METHOD(SplObjectStorage, __unserialize) Z_TYPE_P(storage_zv) != IS_ARRAY || Z_TYPE_P(members_zv) != IS_ARRAY) { zend_throw_exception(spl_ce_UnexpectedValueException, "Incomplete or ill-typed serialization data", 0); - return; + RETURN_THROWS(); } if (zend_hash_num_elements(Z_ARRVAL_P(storage_zv)) % 2 != 0) { zend_throw_exception(spl_ce_UnexpectedValueException, "Odd number of elements", 0); - return; + RETURN_THROWS(); } key = NULL; @@ -929,7 +929,7 @@ SPL_METHOD(SplObjectStorage, __unserialize) if (key) { if (Z_TYPE_P(key) != IS_OBJECT) { zend_throw_exception(spl_ce_UnexpectedValueException, "Non-object key", 0); - return; + RETURN_THROWS(); } spl_object_storage_attach(intern, key, val); @@ -1071,14 +1071,14 @@ SPL_METHOD(MultipleIterator, attachIterator) if (Z_TYPE_P(info) != IS_LONG && Z_TYPE_P(info) != IS_STRING) { zend_throw_exception(spl_ce_InvalidArgumentException, "Info must be NULL, integer or string", 0); - return; + RETURN_THROWS(); } zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos); while ((element = zend_hash_get_current_data_ptr_ex(&intern->storage, &intern->pos)) != NULL) { if (fast_is_identical_function(info, &element->inf)) { zend_throw_exception(spl_ce_InvalidArgumentException, "Key duplication error", 0); - return; + RETURN_THROWS(); } zend_hash_move_forward_ex(&intern->storage, &intern->pos); } diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 3f4bba2191..b27e001791 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -113,20 +113,20 @@ PHP_METHOD(sqlite3, open) if (db_obj->initialised) { zend_throw_exception(zend_ce_exception, "Already initialised DB Object", 0); - return; + RETURN_THROWS(); } if (filename_len != 0 && (filename_len != sizeof(":memory:")-1 || memcmp(filename, ":memory:", sizeof(":memory:")-1) != 0)) { if (!(fullpath = expand_filepath(filename, NULL))) { zend_throw_exception(zend_ce_exception, "Unable to expand filepath", 0); - return; + RETURN_THROWS(); } if (php_check_open_basedir(fullpath)) { zend_throw_exception_ex(zend_ce_exception, 0, "open_basedir prohibits opening %s", fullpath); efree(fullpath); - return; + RETURN_THROWS(); } } else { /* filename equals "" or ":memory:" */ @@ -153,7 +153,7 @@ PHP_METHOD(sqlite3, open) if (sqlite3_key(db_obj->db, encryption_key, encryption_key_len) != SQLITE_OK) { sqlite3_close(db_obj->db); zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", sqlite3_errmsg(db_obj->db)); - return; + RETURN_THROWS(); } } #endif diff --git a/ext/standard/array.c b/ext/standard/array.c index 4fbd5506ea..70b793a905 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -4711,7 +4711,7 @@ static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compa if (argc < req_args) { zend_argument_count_error("At least %d parameters are required, %d given", req_args, argc); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), param_spec, &args, &argc, &BG(user_compare_fci), &BG(user_compare_fci_cache)) == FAILURE) { @@ -4805,7 +4805,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int if (ZEND_NUM_ARGS() < req_args) { zend_argument_count_error("At least %d parameters are required, %d given", req_args, ZEND_NUM_ARGS()); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), param_spec, &args, &arr_argc, &fci1, &fci1_cache) == FAILURE) { @@ -4857,7 +4857,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int if (ZEND_NUM_ARGS() < req_args) { zend_argument_count_error("At least %d parameters are required, %d given", req_args, ZEND_NUM_ARGS()); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), param_spec, &args, &arr_argc, &fci1, &fci1_cache, &fci2, &fci2_cache) == FAILURE) { @@ -5104,7 +5104,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty if (data_compare_type == DIFF_COMP_DATA_USER) { if (argc < 3) { zend_argument_count_error("At least 3 parameters are required, %d given", ZEND_NUM_ARGS()); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "+f", &args, &argc, &BG(user_compare_fci), &BG(user_compare_fci_cache)) == FAILURE) { RETURN_THROWS(); @@ -5113,7 +5113,7 @@ static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_ty } else { if (argc < 2) { zend_argument_count_error("At least 2 parameters are required, %d given", ZEND_NUM_ARGS()); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), "+", &args, &argc) == FAILURE) { RETURN_THROWS(); @@ -5210,7 +5210,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ if (ZEND_NUM_ARGS() < req_args) { zend_argument_count_error("At least %d parameters are required, %d given", req_args, ZEND_NUM_ARGS()); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), param_spec, &args, &arr_argc, &fci1, &fci1_cache) == FAILURE) { @@ -5262,7 +5262,7 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_ if (ZEND_NUM_ARGS() < req_args) { zend_argument_count_error("At least %d parameters are required, %d given", req_args, ZEND_NUM_ARGS()); - return; + RETURN_THROWS(); } if (zend_parse_parameters(ZEND_NUM_ARGS(), param_spec, &args, &arr_argc, &fci1, &fci1_cache, &fci2, &fci2_cache) == FAILURE) { @@ -5459,7 +5459,7 @@ PHP_FUNCTION(array_diff) if (ZEND_NUM_ARGS() < 2) { zend_argument_count_error("At least 2 parameters are required, %d given", ZEND_NUM_ARGS()); - return; + RETURN_THROWS(); } ZEND_PARSE_PARAMETERS_START(1, -1) diff --git a/ext/standard/math.c b/ext/standard/math.c index 053c26b829..5b9fa98b73 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1236,12 +1236,12 @@ PHP_FUNCTION(intdiv) if (divisor == 0) { zend_throw_exception_ex(zend_ce_division_by_zero_error, 0, "Division by zero"); - return; + RETURN_THROWS(); } else if (divisor == -1 && dividend == ZEND_LONG_MIN) { /* Prevent overflow error/crash ... really should not happen: We don't return a float here as that violates function contract */ zend_throw_exception_ex(zend_ce_arithmetic_error, 0, "Division of PHP_INT_MIN by -1 is not an integer"); - return; + RETURN_THROWS(); } RETURN_LONG(dividend / divisor); diff --git a/ext/standard/random.c b/ext/standard/random.c index ecc9b61eee..9a3e1b33a0 100644 --- a/ext/standard/random.c +++ b/ext/standard/random.c @@ -206,7 +206,7 @@ PHP_FUNCTION(random_bytes) if (size < 1) { zend_throw_exception(zend_ce_error, "Length must be greater than 0", 0); - return; + RETURN_THROWS(); } bytes = zend_string_alloc(size, 0); @@ -281,11 +281,11 @@ PHP_FUNCTION(random_int) if (min > max) { zend_throw_exception(zend_ce_error, "Minimum value must be less than or equal to the maximum value", 0); - return; + RETURN_THROWS(); } if (php_random_int_throw(min, max, &result) == FAILURE) { - return; + RETURN_THROWS(); } RETURN_LONG(result); |