Add integer overflow checks to 6 allocation size calculations#7
Open
kodareef5 wants to merge 1 commit intoisc-projects:masterfrom
Open
Add integer overflow checks to 6 allocation size calculations#7kodareef5 wants to merge 1 commit intoisc-projects:masterfrom
kodareef5 wants to merge 1 commit intoisc-projects:masterfrom
Conversation
1. common/tree.c: Change new_len from signed int to unsigned int and add UINT_MAX/2 check before doubling. Signed int overflow in the doubling loop is undefined behavior that could cause infinite loop. 2. common/parse.c: Check universe_max > INT_MAX/2 before doubling the option space array. 3. omapip/alloc.c: Check count * sizeof(omapi_addr_t) + sizeof(list) does not overflow size_t before allocation. 4. omapip/array.c: Check (max + delta) * sizeof(char *) does not overflow size_t before array growth allocation. 5. common/options.c:3664: Check length * 4 + 3 does not overflow unsigned int in FQDN option buffer allocation. 6. common/options.c:2738: Check num_opts * 2 does not overflow int in server ORO buffer allocation.
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.
Six sites across five files compute allocation sizes with unchecked arithmetic that can overflow:
common/tree.c —
new_lenisint(signed) but doublesds->len(unsigned). Signed overflow is undefined behavior; a compiler may assume it never happens and optimize the loop into an infinite loop. Changed tounsigned intwithUINT_MAX/2guard.common/parse.c —
universe_max * 2can overflowintwhen the option space array grows. AddedINT_MAX/2check before doubling.omapip/alloc.c —
count * sizeof(omapi_addr_t) + sizeof(omapi_addr_list_t)can overflowsize_ton 32-bit. Added overflow check beforedmalloc.omapip/array.c —
(array->max + delta) * sizeof(char *)can overflow whenindexis nearINT_MAX. AddedSIZE_MAXcheck beforedmalloc.common/options.c:3664 —
3 + (length * 4)can overflowunsigned int. Added(UINT_MAX - 3) / 4check.common/options.c:2738 —
num_opts * 2can overflowint. AddedINT_MAX/2check.All overflow checks use the existing error handling patterns (
return 0,return ISC_R_NOMEMORY, orlog_fatal). Builds clean with-Wall -Werror.