Skip to content

Add integer overflow checks to 6 allocation size calculations#7

Open
kodareef5 wants to merge 1 commit intoisc-projects:masterfrom
kodareef5:fix-integer-overflow-hardening
Open

Add integer overflow checks to 6 allocation size calculations#7
kodareef5 wants to merge 1 commit intoisc-projects:masterfrom
kodareef5:fix-integer-overflow-hardening

Conversation

@kodareef5
Copy link

Six sites across five files compute allocation sizes with unchecked arithmetic that can overflow:

  1. common/tree.cnew_len is int (signed) but doubles ds->len (unsigned). Signed overflow is undefined behavior; a compiler may assume it never happens and optimize the loop into an infinite loop. Changed to unsigned int with UINT_MAX/2 guard.

  2. common/parse.cuniverse_max * 2 can overflow int when the option space array grows. Added INT_MAX/2 check before doubling.

  3. omapip/alloc.ccount * sizeof(omapi_addr_t) + sizeof(omapi_addr_list_t) can overflow size_t on 32-bit. Added overflow check before dmalloc.

  4. omapip/array.c(array->max + delta) * sizeof(char *) can overflow when index is near INT_MAX. Added SIZE_MAX check before dmalloc.

  5. common/options.c:36643 + (length * 4) can overflow unsigned int. Added (UINT_MAX - 3) / 4 check.

  6. common/options.c:2738num_opts * 2 can overflow int. Added INT_MAX/2 check.

All overflow checks use the existing error handling patterns (return 0, return ISC_R_NOMEMORY, or log_fatal). Builds clean with -Wall -Werror.

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.
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