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

fix: resolve UBSAN violations in the codebase #4722

Merged
merged 9 commits into from
Aug 23, 2024

Conversation

boquan-fang
Copy link
Contributor

@boquan-fang boquan-fang commented Aug 21, 2024

Resolved issues:

Partial for issue #4684.

Description of changes:

  • Change s2n_test.h MACRO EXPECT_BYTEARRAY_EQUAL. Add checks for the inputed length l.
  • Proceed regardless of inputs, if length l is set to 0, and perform memcmp is l is not set to 0.
  • Fix all null arithmetic in s2n_stuffer.c and s2n_test_server_client.c.

Call-outs:

UBSAN build command hasn't been integrated into the CI. Need to fix that problem in order to meet the issue's second requirement.

There are 68 tests that pass NULL to s2n_stuffer->blob.data.

Testing:

  • Run CTEST_PARALLEL test. It passes all tests without triggering UBSAN violation.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

* make EXPECT_BYTEARRAY_EQUAL to do memcmp when length input isn't zero
* proceed regardless of inputs if length is set to be zero
* set results of null arithmetic to null pointer instead of undefine
@github-actions github-actions bot added the s2n-core team label Aug 21, 2024
@boquan-fang boquan-fang marked this pull request as ready for review August 21, 2024 20:46
Boquan Fang added 2 commits August 22, 2024 16:55
…ion.

* Check for s2n_stuffer_write_bytes. Exit if no byte is written.
* Check s2n_stuffer_shift's read_cursor. Don't add read_cursor to
  blob.data if it is zero.
* Simplify EXPECT_BYTEARRAY_EQUAL logic.
stuffer/s2n_stuffer.c Outdated Show resolved Hide resolved
* Update the comments in s2n_stuffer_shift.
@boquan-fang boquan-fang requested a review from jmayclin August 22, 2024 18:47
stuffer/s2n_stuffer.c Outdated Show resolved Hide resolved
tests/s2n_test.h Outdated Show resolved Hide resolved
tests/testlib/s2n_test_server_client.c Outdated Show resolved Hide resolved
stuffer/s2n_stuffer.c Outdated Show resolved Hide resolved
* Modifying comments to be more precise.
* Deleteling some unnecessary white space.
@boquan-fang boquan-fang requested a review from lrstewart August 22, 2024 23:20
tests/s2n_test.h Outdated Show resolved Hide resolved
tests/testlib/s2n_test_server_client.c Outdated Show resolved Hide resolved
* relocate EXPECT_BYTEARRAY_EQUAL comments to within the function
* change variable name to make it more specific
@boquan-fang boquan-fang requested a review from lrstewart August 22, 2024 23:47
tests/s2n_test.h Outdated Show resolved Hide resolved
* remove comments for MACRO
* comdense comments for stuffer and test
@boquan-fang boquan-fang requested a review from lrstewart August 23, 2024 00:28
stuffer/s2n_stuffer.c Outdated Show resolved Hide resolved
Change comment location

Co-authored-by: Lindsay Stewart <[email protected]>
@boquan-fang boquan-fang enabled auto-merge (squash) August 23, 2024 17:02
@boquan-fang boquan-fang merged commit 3728361 into aws:main Aug 23, 2024
36 checks passed
@boquan-fang boquan-fang deleted the ubsan-fix branch December 18, 2024 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants