Skip to content

cipher: fix error checks for EVP_CIPHER_CTX_ctrl()#1041

Merged
rhenium merged 1 commit intoruby:masterfrom
ndossche:clesss-14
Apr 29, 2026
Merged

cipher: fix error checks for EVP_CIPHER_CTX_ctrl()#1041
rhenium merged 1 commit intoruby:masterfrom
ndossche:clesss-14

Conversation

@ndossche
Copy link
Copy Markdown
Contributor

The return value behaviour isn't explicitly documented for OpenSSL. For LibreSSL, it says [1]:

EVP_CIPHER_CTX_ctrl() returns 1 for success or 0 for failure.
Some implementations may return negative values for some errors.

So it appears that we need to check for <= 0 instead of !0. Furthermore, I looked for how OpenSSL does this and found it also does things inconsistently. I submitted a PR to check for <= 0 which was accepted [2].

[1] https://man.openbsd.org/EVP_CIPHER_CTX_ctrl.3
[2] openssl/openssl#30923

This was found by a hybrid static-dynamic analyser that looks for inconsistent handling of error checks in bindings.

The return value behaviour isn't explicitly documented for OpenSSL.
For LibreSSL, it says [1]:

> EVP_CIPHER_CTX_ctrl() returns 1 for success or 0 for failure.
> Some implementations may return negative values for some errors.

So it appears that we need to check for `<= 0` instead of `!0`.
Furthermore, I looked for how OpenSSL does this and found it also does
things inconsistently. I submitted a PR to check for `<= 0` which was
accepted [2].

[1] https://man.openbsd.org/EVP_CIPHER_CTX_ctrl.3
[2] openssl/openssl#30923
Copy link
Copy Markdown
Member

@rhenium rhenium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@rhenium rhenium merged commit 1d46d12 into ruby:master Apr 29, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants