fix(psk): Prevent internal error with uninitialized PSK#5676
Open
Ignacio-Trottaa wants to merge 1 commit intoaws:mainfrom
Open
fix(psk): Prevent internal error with uninitialized PSK#5676Ignacio-Trottaa wants to merge 1 commit intoaws:mainfrom
Ignacio-Trottaa wants to merge 1 commit intoaws:mainfrom
Conversation
When s2n_offered_psk_list_choose_psk was called with an s2n_offered_psk struct that was allocated but not initialized, it would result in a NULL pointer dereference and an internal error. This change adds a check to ensure the psk's identity data is not NULL before proceeding, returning a usage error (S2N_ERR_NULL) instead. A unit test is also added to verify this behavior. Fixes: aws#5085
Contributor
|
Hi @Ignacio-Trottaa, thanks for your contribution! The testing section mentioned you added a new unit test, but I didn't see it in the file diff. Do you plan to add the test to this PR? Your fix looks correct though! |
Author
|
Hi @CarolYeh910, thanks for your feedback! Sorry about the unit test; I mentioned I uploaded it, but... I forgot to upload it along with the correction. |
Contributor
|
Hey are you still working on this? We don't want to merge this without a unit test. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: Handle uninitialized PSK in choose_psk
When s2n_offered_psk_list_choose_psk was called with an s2n_offered_psk
struct that was allocated but not initialized, it would result in a
NULL pointer dereference and an internal error.
This change adds a check to ensure the psk's identity data is not
NULL before proceeding, returning a usage error (S2N_ERR_NULL) instead.
A unit test is also added to verify this behavior.
Fixes: #5085
Goal
Prevent an internal error when
s2n_offered_psk_list_choose_pskis called with an uninitialized PSK.Why
Calling the function with a PSK that has a
NULLidentity data pointer causes a crash. The function should fail gracefully with a usage error instead of an internal one, improving the library's robustness. This addresses issue #5085.How
A
POSIX_ENSURE_REFcheck is added at the beginning of the function to validate thatpsk->identity.datais not NULL. If it is, the function now returnsS2N_ERR_NULL.Callouts
None. The fix is straightforward.
Testing
A new unit test,
s2n_offered_psk_list_choose_psk_with_uninitialized_psk, was added. This test replicates the failing scenario and asserts that the function now correctly returns a failure with theS2N_ERR_NULLerror code. All existing tests pass.Related
Fixes #5085
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.