Skip to content

Commit a22eb4d

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix error return check of EVP_CIPHER_CTX_ctrl() Fix memleak on failure in collator_get_sort_key()
2 parents 1089896 + 0f731b4 commit a22eb4d

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

ext/intl/collator/collator_sort.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ PHP_FUNCTION( collator_get_sort_key )
553553
key_len = ucol_getSortKey(co->ucoll, ustr, ustr_len, (uint8_t*)ZSTR_VAL(key_str), key_len);
554554
efree( ustr );
555555
if(!key_len) {
556+
zend_string_efree(key_str);
556557
RETURN_FALSE;
557558
}
558559
ZSTR_LEN(key_str) = key_len - 1;

ext/openssl/openssl_backend_common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ zend_result php_openssl_validate_iv(const char **piv, size_t *piv_len, size_t iv
16711671
char *iv_new;
16721672

16731673
if (mode->is_aead) {
1674-
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_ivlen_flag, *piv_len, NULL) != 1) {
1674+
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_ivlen_flag, *piv_len, NULL) <= 0) {
16751675
php_error_docref(NULL, E_WARNING, "Setting of IV length for AEAD mode failed");
16761676
return FAILURE;
16771677
}
@@ -1742,15 +1742,15 @@ zend_result php_openssl_cipher_init(const EVP_CIPHER *cipher_type,
17421742
return FAILURE;
17431743
}
17441744
if (mode->set_tag_length_always || (enc && mode->set_tag_length_when_encrypting)) {
1745-
if (!EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, NULL)) {
1745+
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, NULL) <= 0) {
17461746
php_error_docref(NULL, E_WARNING, "Setting tag length for AEAD cipher failed");
17471747
return FAILURE;
17481748
}
17491749
}
17501750
if (!enc && tag && tag_len > 0) {
17511751
if (!mode->is_aead) {
17521752
php_error_docref(NULL, E_WARNING, "The tag cannot be used because the cipher algorithm does not support AEAD");
1753-
} else if (!EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, (unsigned char *) tag)) {
1753+
} else if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, (unsigned char *) tag) <= 0) {
17541754
php_error_docref(NULL, E_WARNING, "Setting tag for AEAD cipher decryption failed");
17551755
return FAILURE;
17561756
}
@@ -1886,7 +1886,7 @@ PHP_OPENSSL_API zend_string* php_openssl_encrypt(
18861886
if (mode.is_aead && tag) {
18871887
zend_string *tag_str = zend_string_alloc(tag_len, 0);
18881888

1889-
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode.aead_get_tag_flag, tag_len, ZSTR_VAL(tag_str)) == 1) {
1889+
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode.aead_get_tag_flag, tag_len, ZSTR_VAL(tag_str)) <= 0) {
18901890
ZSTR_VAL(tag_str)[tag_len] = '\0';
18911891
ZSTR_LEN(tag_str) = tag_len;
18921892
ZEND_TRY_ASSIGN_REF_NEW_STR(tag, tag_str);

0 commit comments

Comments
 (0)