Skip to content

fix: replace uint8_t in for loops#5619

Merged
CarolYeh910 merged 1 commit intoaws:mainfrom
CarolYeh910:fix-for-loop-range
Nov 17, 2025
Merged

fix: replace uint8_t in for loops#5619
CarolYeh910 merged 1 commit intoaws:mainfrom
CarolYeh910:fix-for-loop-range

Conversation

@CarolYeh910
Copy link
Copy Markdown
Contributor

@CarolYeh910 CarolYeh910 commented Nov 17, 2025

Goal

Prevent potential timeout in unit tests

Why

The for loops in s2n_security_policy_get_version() and s2n_security_policy_supports_tls13() use uint8_t i = 0, which can only hold values from 0 to 255. Currently, s2n-tls has only 140 security policies, so everything is fine. However, as we add more policies in the future, the number of policies will eventually exceed the range of uint8_t.

Additionally, some unit tests define their own testing policies that do not exist in the security_policy_selection array. In this case, the only way to exit these for loops is to hit the security_policy_selection[i].version == NULL condition (i.e. the last element in security_policy_selection). If the last policy with version = NULL is out of range, these two for loops will become infinite and lead to timeout failure.

How

Replace uint8_t with another date type of a larger range like size_t

Testing

I found timeout failure in 25 s2n-tls unit tests by creating 120 copies of the test_all policy and exceeding the uint8_t range. After applying the fix in this PR, all the timeout failures went away.

I don't think our CI jobs enable the --timeout flag, so I only ran the testing locally via

CTEST_PARALLEL_LEVEL=$(nproc) ctest --test-dir build --timeout 120

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

@github-actions github-actions bot added the s2n-core team label Nov 17, 2025
@CarolYeh910 CarolYeh910 changed the title fix: replace uint8_t in for loop fix: replace uint8_t in for loops Nov 17, 2025
@CarolYeh910 CarolYeh910 added this pull request to the merge queue Nov 17, 2025
Merged via the queue into aws:main with commit ea95208 Nov 17, 2025
53 checks passed
@CarolYeh910 CarolYeh910 deleted the fix-for-loop-range branch November 17, 2025 21:00
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