Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly detect when allocation fails and return correct #67

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

normanmaurer
Copy link
Member

value

Motivation:

The BoringSSL class handles the Java->Native (BoringSSL) calls. In EVP_HPKE_CTX_new_or_throw it checks to ensure that a new EVP_HPKE_CTX is properly allocated (in the native heap) and that a pointer to it is returned. However, it checks this value against -1 when a failure of the EVP_HPKE_CTX_new() native method (from BoringSSL) return a NULL (or 0) upon failure, not a -1. This means that a failed context creation will result in a NULL pointer being return and later dereferenced by native code. The same problem exists for EVP_HPKE_CTX_new().

Modifications:

Detect NULL and return -1 so we correctly handle it in the java layer

Result:

No more possible dereferencing of NULL pointer

 value

Motivation:

The `BoringSSL` class handles the Java->Native (BoringSSL) calls. In `EVP_HPKE_CTX_new_or_throw` it checks to ensure that a new `EVP_HPKE_CTX`  is properly allocated (in the native heap) and that a pointer to it is returned. However, it checks this value against `-1` when a failure of the `EVP_HPKE_CTX_new()` native method (from BoringSSL) return a `NULL` (or `0`) upon failure, not a `-1`. This means that a failed context creation will result in a `NULL` pointer being return and later dereferenced by native code. The same problem exists for EVP_HPKE_CTX_new().

Modifications:

Detect NULL and return -1 so we correctly handle it in the java layer

Result:

No more possible dereferencing of NULL pointer
@normanmaurer normanmaurer added this to the 0.0.12.Final milestone Jun 5, 2024
@normanmaurer normanmaurer merged commit 1bc5904 into main Jun 5, 2024
9 checks passed
@normanmaurer normanmaurer deleted the return_correct_value branch June 5, 2024 16:49
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.

1 participant