Skip to content

Fix Linux allocation hook calloc overflow handling#3635

Open
fallintoplace wants to merge 1 commit into
apple:mainfrom
fallintoplace:fix/linux-calloc-overflow
Open

Fix Linux allocation hook calloc overflow handling#3635
fallintoplace wants to merge 1 commit into
apple:mainfrom
fallintoplace:fix/linux-calloc-overflow

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Motivation

The Linux allocation-counting hook implements calloc by multiplying count and size before allocating, then zeroing the result unconditionally. If the multiplication overflows, the hook can allocate a smaller buffer than requested. If allocation fails, it can pass NULL to memset.

Modification

This checks for count/size overflow before multiplying, reuses the computed total size, and only zeroes memory after allocation succeeds.

Result

The Linux hook now follows calloc-style failure behavior for overflow and avoids zeroing a NULL pointer on allocation failure.

Validation

  • swift build --package-path IntegrationTests/allocation-counter-tests-framework/template/HookedFunctionsDoHook
  • clang -std=gnu11 -fsyntax-only -U__APPLE__ -IIntegrationTests/allocation-counter-tests-framework/template/HookedFunctionsDoHook/Sources/HookedFunctions/include -IIntegrationTests/allocation-counter-tests-framework/template/AtomicCounter/Sources/AtomicCounter/include IntegrationTests/allocation-counter-tests-framework/template/HookedFunctionsDoHook/Sources/HookedFunctions/src/hooked-functions-unix.c

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