Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,7 @@ PHP NEWS
. deflate_init() now raises a TypeError when the value for option
"level", "memory", "window", or "strategy" is not of type int.
(Weilin Du)
. inflate_init() now raises a TypeError when the value for option
"window" is not of type int. (Weilin Du)

<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ PHP 8.6 UPGRADE NOTES
- Zlib:
. deflate_init() now raises a TypeError when the value for option
"level", "memory", "window", or "strategy" is not of type int.
. inflate_init() now raises a TypeError when the value for option
"window" is not of type int.

========================================
2. New Features
Expand Down
10 changes: 5 additions & 5 deletions ext/openssl/openssl_backend_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void php_openssl_add_assoc_name_entry(zval * val, char * key, X509_NAME * name,

void php_openssl_add_assoc_asn1_string(zval * val, char * key, ASN1_STRING * str)
{
add_assoc_stringl(val, key, (char *)str->data, str->length);
add_assoc_stringl(val, key, (const char *)ASN1_STRING_get0_data(str), ASN1_STRING_length(str));
}

time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
Expand Down Expand Up @@ -140,12 +140,12 @@ time_t php_openssl_asn1_time_to_time_t(ASN1_UTCTIME * timestr)
}

if (timestr_len < 13) {
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data);
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
return (time_t)-1;
}

if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME && timestr_len < 15) {
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", timestr->data);
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
return (time_t)-1;
}

Expand Down Expand Up @@ -626,8 +626,8 @@ int openssl_x509v3_subjectAltName(BIO *bio, X509_EXTENSION *extension)
}

extension_data = X509_EXTENSION_get_data(extension);
p = extension_data->data;
length = extension_data->length;
p = ASN1_STRING_get0_data(extension_data);
length = ASN1_STRING_length(extension_data);
if (method->it) {
names = (GENERAL_NAMES*) (ASN1_item_d2i(NULL, &p, length,
ASN1_ITEM_ptr(method->it)));
Expand Down
14 changes: 7 additions & 7 deletions ext/openssl/xp_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
}
OPENSSL_free(cert_name);
} else if (san->type == GEN_IPADD) {
if (san->d.iPAddress->length == 4) {
if (ASN1_STRING_length(san->d.iPAddress) == 4) {
snprintf(ipbuffer, sizeof(ipbuffer), "%d.%d.%d.%d",
san->d.iPAddress->data[0],
san->d.iPAddress->data[1],
san->d.iPAddress->data[2],
san->d.iPAddress->data[3]
ASN1_STRING_get0_data(san->d.iPAddress)[0],
ASN1_STRING_get0_data(san->d.iPAddress)[1],
ASN1_STRING_get0_data(san->d.iPAddress)[2],
ASN1_STRING_get0_data(san->d.iPAddress)[3]
);
if (strcasecmp(subject_name, (const char*)ipbuffer) == 0) {
sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);
Expand All @@ -506,9 +506,9 @@ static bool php_openssl_matches_san_list(X509 *peer, const char *subject_name) /
}
}
#ifdef HAVE_IPV6_SAN
else if (san->d.ip->length == 16 && subject_name_is_ipv6) {
else if (ASN1_STRING_length(san->d.ip) == 16 && subject_name_is_ipv6) {
ipbuffer[0] = 0;
EXPAND_IPV6_ADDRESS(ipbuffer, san->d.iPAddress->data);
EXPAND_IPV6_ADDRESS(ipbuffer, ASN1_STRING_get0_data(san->d.iPAddress));
if (strcasecmp((const char*)subject_name_ipv6_expanded, (const char*)ipbuffer) == 0) {
sk_GENERAL_NAME_pop_free(alt_names, GENERAL_NAME_free);

Expand Down
20 changes: 12 additions & 8 deletions ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void phar_split_cache_list(void) /* {{{ */
len = strlen(key);
}

if (SUCCESS == phar_open_from_filename(key, len, NULL, 0, 0, &phar, NULL)) {
if (SUCCESS == phar_open_from_filename(key, len, NULL, 0, &phar, NULL)) {
phar->phar_pos = i++;
php_stream_close(phar->fp);
phar->fp = NULL;
Expand Down Expand Up @@ -1507,7 +1507,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 6, 7) zend_result phar_create_or_parse_filename(z
* that the manifest is proper, then pass it to phar_parse_pharfile(). SUCCESS
* or FAILURE is returned and pphar is set to a pointer to the phar's manifest
*/
zend_result phar_open_from_filename(char *fname, size_t fname_len, const char *alias, size_t alias_len, uint32_t options, phar_archive_data** pphar, char **error) /* {{{ */
zend_result phar_open_from_filename(char *fname, size_t fname_len, const zend_string *alias, uint32_t options, phar_archive_data** pphar, char **error) /* {{{ */
{
php_stream *fp;
zend_string *actual;
Expand All @@ -1521,7 +1521,9 @@ zend_result phar_open_from_filename(char *fname, size_t fname_len, const char *a
is_data = true;
}

if (phar_open_parsed_phar(fname, fname_len, alias, alias_len, is_data, options, pphar, error) == SUCCESS) {
const char *alias_cstr = alias ? ZSTR_VAL(alias) : NULL;
size_t alias_len = alias ? ZSTR_LEN(alias) : 0;
if (phar_open_parsed_phar(fname, fname_len, alias_cstr, alias_len, is_data, options, pphar, error) == SUCCESS) {
return SUCCESS;
} else if (error && *error) {
return FAILURE;
Expand Down Expand Up @@ -1549,7 +1551,7 @@ zend_result phar_open_from_filename(char *fname, size_t fname_len, const char *a
fname_len = ZSTR_LEN(actual);
}

zend_result ret = phar_open_from_fp(fp, fname, fname_len, alias, alias_len, options, pphar, error);
zend_result ret = phar_open_from_fp(fp, fname, fname_len, alias_cstr, alias_len, options, pphar, error);

if (actual) {
zend_string_release_ex(actual, 0);
Expand Down Expand Up @@ -2252,7 +2254,7 @@ zend_string* phar_split_fname(const char *filename, size_t filename_len, zend_st
* Invoked when a user calls Phar::mapPhar() from within an executing .phar
* to set up its manifest directly
*/
ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(const char *alias, size_t alias_len, char **error) /* {{{ */
ZEND_ATTRIBUTE_NONNULL_ARGS(2) zend_result phar_open_executed_filename(const zend_string *alias, char **error) /* {{{ */
{
*error = NULL;

Expand All @@ -2263,7 +2265,9 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(const cha
return FAILURE;
}

if (phar_open_parsed_phar(ZSTR_VAL(fname), ZSTR_LEN(fname), alias, alias_len, false, REPORT_ERRORS, NULL, NULL) == SUCCESS) {
const char *alias_cstr = alias ? ZSTR_VAL(alias) : NULL;
size_t alias_len = alias ? ZSTR_LEN(alias) : 0;
if (phar_open_parsed_phar(ZSTR_VAL(fname), ZSTR_LEN(fname), alias_cstr, alias_len, false, REPORT_ERRORS, NULL, NULL) == SUCCESS) {
return SUCCESS;
}

Expand Down Expand Up @@ -2292,7 +2296,7 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(const cha
fname = actual;
}

zend_result ret = phar_open_from_fp(fp, ZSTR_VAL(fname), ZSTR_LEN(fname), alias, alias_len, REPORT_ERRORS, NULL, error);
zend_result ret = phar_open_from_fp(fp, ZSTR_VAL(fname), ZSTR_LEN(fname), alias_cstr, alias_len, REPORT_ERRORS, NULL, error);

if (actual) {
zend_string_release_ex(actual, 0);
Expand Down Expand Up @@ -3156,7 +3160,7 @@ static zend_op_array *phar_compile_file(zend_file_handle *file_handle, int type)
return phar_orig_compile_file(file_handle, type);
}
if (strstr(ZSTR_VAL(file_handle->filename), ".phar") && !strstr(ZSTR_VAL(file_handle->filename), "://")) {
if (SUCCESS == phar_open_from_filename(ZSTR_VAL(file_handle->filename), ZSTR_LEN(file_handle->filename), NULL, 0, 0, &phar, NULL)) {
if (SUCCESS == phar_open_from_filename(ZSTR_VAL(file_handle->filename), ZSTR_LEN(file_handle->filename), NULL, 0, &phar, NULL)) {
if (phar->is_zip || phar->is_tar) {
zend_file_handle f;

Expand Down
4 changes: 2 additions & 2 deletions ext/phar/phar_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ void phar_object_init(void);
void phar_destroy_phar_data(phar_archive_data *phar);

ZEND_ATTRIBUTE_NONNULL zend_result phar_postprocess_file(phar_entry_data *idata, uint32_t crc32, char **error, int process_zip);
zend_result phar_open_from_filename(char *fname, size_t fname_len, const char *alias, size_t alias_len, uint32_t options, phar_archive_data** pphar, char **error);
zend_result phar_open_from_filename(char *fname, size_t fname_len, const zend_string *alias, uint32_t options, phar_archive_data** pphar, char **error);
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 6, 7) zend_result phar_open_or_create_filename(zend_string *fname, const char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error);
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 6, 7) zend_result phar_create_or_parse_filename(zend_string *fname, const char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error);
ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(const char *alias, size_t alias_len, char **error);
ZEND_ATTRIBUTE_NONNULL_ARGS(2) zend_result phar_open_executed_filename(const zend_string *alias, char **error);
zend_result phar_free_alias(const phar_archive_data *phar);
phar_archive_data* phar_get_archive(const char *fname, size_t fname_len, const char *alias, size_t alias_len, char **error);
zend_result phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type, const char *sig, size_t sig_len, const char *fname, char **signature, size_t *signature_len, char **error);
Expand Down
29 changes: 15 additions & 14 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,8 @@ PHP_METHOD(Phar, webPhar)
zval *mimeoverride = NULL;
zend_fcall_info rewrite_fci = {0};
zend_fcall_info_cache rewrite_fcc;
char *alias = NULL, *error, *index_php = NULL, *ru = NULL;
size_t alias_len = 0, free_pathinfo = 0;
char *error, *index_php = NULL, *ru = NULL;
size_t free_pathinfo = 0;
zend_string *f404 = NULL;
size_t ru_len = 0;
char *fname, *path_info, *mime_type = NULL, *entry, *pt;
Expand All @@ -562,14 +562,15 @@ PHP_METHOD(Phar, webPhar)
phar_entry_info *info = NULL;
size_t sapi_mod_name_len = strlen(sapi_module.name);
phar_action_status status = PHAR_ACT_DO_EXIT;
zend_string *alias = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!S!af!", &alias, &alias_len, &index_php, &index_php_len, &f404, &mimeoverride, &rewrite_fci, &rewrite_fcc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!s!S!af!", &alias, &index_php, &index_php_len, &f404, &mimeoverride, &rewrite_fci, &rewrite_fcc) == FAILURE) {
RETURN_THROWS();
}

phar_request_initialize();

if (phar_open_executed_filename(alias, alias_len, &error) != SUCCESS) {
if (phar_open_executed_filename(alias, &error) != SUCCESS) {
if (error) {
zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);
efree(error);
Expand Down Expand Up @@ -947,17 +948,17 @@ PHP_METHOD(Phar, createDefaultStub)
/* {{{ Reads the currently executed file (a phar) and registers its manifest */
PHP_METHOD(Phar, mapPhar)
{
char *alias = NULL, *error;
size_t alias_len = 0;
zend_string *alias = NULL;
char *error;
zend_long dataoffset = 0;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!l", &alias, &alias_len, &dataoffset) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!l", &alias, &dataoffset) == FAILURE) {
RETURN_THROWS();
}

phar_request_initialize();

RETVAL_BOOL(phar_open_executed_filename(alias, alias_len, &error) == SUCCESS);
RETVAL_BOOL(phar_open_executed_filename(alias, &error) == SUCCESS);

if (error) {
zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);
Expand All @@ -969,16 +970,16 @@ PHP_METHOD(Phar, mapPhar)
PHP_METHOD(Phar, loadPhar)
{
zend_string *fname;
char *alias = NULL, *error;
size_t alias_len = 0;
zend_string *alias = NULL;
char *error;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|s!", &fname, &alias, &alias_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|S!", &fname, &alias) == FAILURE) {
RETURN_THROWS();
}

phar_request_initialize();

RETVAL_BOOL(phar_open_from_filename(ZSTR_VAL(fname), ZSTR_LEN(fname), alias, alias_len, REPORT_ERRORS, NULL, &error) == SUCCESS);
RETVAL_BOOL(phar_open_from_filename(ZSTR_VAL(fname), ZSTR_LEN(fname), alias, REPORT_ERRORS, NULL, &error) == SUCCESS);

if (error) {
zend_throw_exception_ex(phar_ce_PharException, 0, "%s", error);
Expand Down Expand Up @@ -1265,7 +1266,7 @@ PHP_METHOD(Phar, unlinkArchive)
RETURN_THROWS();
}

if (FAILURE == phar_open_from_filename(ZSTR_VAL(fname), ZSTR_LEN(fname), NULL, 0, REPORT_ERRORS, &phar, &error)) {
if (FAILURE == phar_open_from_filename(ZSTR_VAL(fname), ZSTR_LEN(fname), NULL, REPORT_ERRORS, &phar, &error)) {
if (error) {
zend_throw_exception_ex(phar_ce_PharException, 0, "Unknown phar archive \"%s\": %s", ZSTR_VAL(fname), error);
efree(error);
Expand Down Expand Up @@ -4415,7 +4416,7 @@ PHP_METHOD(PharFileInfo, __construct)
RETURN_THROWS();
}

if (phar_open_from_filename(ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, REPORT_ERRORS, &phar_data, &error) == FAILURE) {
if (phar_open_from_filename(ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, REPORT_ERRORS, &phar_data, &error) == FAILURE) {
zend_string_release_ex(arch, false);
efree(entry);
if (error) {
Expand Down
2 changes: 1 addition & 1 deletion ext/phar/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ php_url* phar_parse_url(php_stream_wrapper *wrapper, const char *filename, const
return NULL;
}
} else {
if (phar_open_from_filename(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, options, NULL, &error) == FAILURE)
if (phar_open_from_filename(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, options, NULL, &error) == FAILURE)
{
if (error) {
if (!(options & PHP_STREAM_URL_STAT_QUIET)) {
Expand Down
16 changes: 16 additions & 0 deletions ext/zlib/tests/inflate_init_window_type_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
inflate_init(): window option type validation
--EXTENSIONS--
zlib
--FILE--
<?php

try {
inflate_init(ZLIB_ENCODING_DEFLATE, ['window' => []]);
} catch (TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
inflate_init(): Argument #2 ($options) the value for option "window" must be of type int, array given
8 changes: 3 additions & 5 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,16 +885,14 @@ PHP_FUNCTION(inflate_init)
zend_long encoding, window = 15;
char *dict = NULL;
size_t dictlen = 0;
HashTable *options = NULL;
zval *option_buffer;
HashTable *options = (HashTable *) &zend_empty_array;

if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l|H", &encoding, &options)) {
RETURN_THROWS();
}

if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
ZVAL_DEINDIRECT(option_buffer);
window = zval_get_long(option_buffer);
if (!zlib_get_long_option(options, ZEND_STRL("window"), &window)) {
RETURN_THROWS();
}
if (window < 8 || window > 15) {
zend_value_error("zlib window size (logarithm) (" ZEND_LONG_FMT ") must be within 8..15", window);
Expand Down
Loading