Skip to content

Commit 5525e66

Browse files
committed
Fix error return check of EVP_CIPHER_CTX_ctrl()
OpenSSL can return -1 on error [1, 2], and OpenBSD's docs confirm this [3]. Existing checks check for 1 for the success value, so do the same. [1] https://github.com/openssl/openssl/blob/b3161bd9a9329be3d6bf6b29a06835e2721898bb/crypto/evp/evp_enc.c#L1530-L1531 [2] https://github.com/openssl/openssl/blob/b3161bd9a9329be3d6bf6b29a06835e2721898bb/crypto/evp/evp_enc.c#L1611 [3] https://man.openbsd.org/EVP_CIPHER_CTX_ctrl.3
1 parent aee1d7f commit 5525e66

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/openssl/openssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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) != 1) {
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) != 1) {
75597559
php_error_docref(NULL, E_WARNING, "Setting tag for AEAD cipher decryption failed");
75607560
return FAILURE;
75617561
}

0 commit comments

Comments
 (0)