Skip to content

Commit cd87223

Browse files
committed
1 parent b495ce0 commit cd87223

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ PHP NEWS
4242
stream_socket_server). (Jakub Zelenka)
4343
. Fixed bug GH-18986 (OpenSSL backend: incorrect RAND_{load,write}_file()
4444
return value check). (nielsdos, botovq)
45+
. Fix error return check of EVP_CIPHER_CTX_ctrl(). (nielsdos)
4546

4647
- PCNTL:
4748
. Fixed bug GH-18958 (Fatal error during shutdown after pcntl_rfork() or

ext/openssl/openssl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7475,7 +7475,7 @@ static int php_openssl_validate_iv(const char **piv, size_t *piv_len, size_t iv_
74757475
char *iv_new;
74767476

74777477
if (mode->is_aead) {
7478-
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_ivlen_flag, *piv_len, NULL) != 1) {
7478+
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_ivlen_flag, *piv_len, NULL) <= 0) {
74797479
php_error_docref(NULL, E_WARNING, "Setting of IV length for AEAD mode failed");
74807480
return FAILURE;
74817481
}
@@ -7547,15 +7547,15 @@ static int php_openssl_cipher_init(const EVP_CIPHER *cipher_type,
75477547
return FAILURE;
75487548
}
75497549
if (mode->set_tag_length_always || (enc && mode->set_tag_length_when_encrypting)) {
7550-
if (!EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, NULL)) {
7550+
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, NULL) <= 0) {
75517551
php_error_docref(NULL, E_WARNING, "Setting tag length for AEAD cipher failed");
75527552
return FAILURE;
75537553
}
75547554
}
75557555
if (!enc && tag && tag_len > 0) {
75567556
if (!mode->is_aead) {
75577557
php_error_docref(NULL, E_WARNING, "The tag cannot be used because the cipher algorithm does not support AEAD");
7558-
} else if (!EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, (unsigned char *) tag)) {
7558+
} else if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode->aead_set_tag_flag, tag_len, (unsigned char *) tag) <= 0) {
75597559
php_error_docref(NULL, E_WARNING, "Setting tag for AEAD cipher decryption failed");
75607560
return FAILURE;
75617561
}
@@ -7693,7 +7693,7 @@ PHP_OPENSSL_API zend_string* php_openssl_encrypt(
76937693
if (mode.is_aead && tag) {
76947694
zend_string *tag_str = zend_string_alloc(tag_len, 0);
76957695

7696-
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode.aead_get_tag_flag, tag_len, ZSTR_VAL(tag_str)) == 1) {
7696+
if (EVP_CIPHER_CTX_ctrl(cipher_ctx, mode.aead_get_tag_flag, tag_len, ZSTR_VAL(tag_str)) > 0) {
76977697
ZSTR_VAL(tag_str)[tag_len] = '\0';
76987698
ZSTR_LEN(tag_str) = tag_len;
76997699
ZEND_TRY_ASSIGN_REF_NEW_STR(tag, tag_str);

0 commit comments

Comments
 (0)