Skip to content

[programs] guard mallocAndJoin2Dir against size_t overflow#4661

Open
Wingingbump wants to merge 1 commit into
facebook:devfrom
Wingingbump:fix/util-mallocAndJoin2Dir-overflow
Open

[programs] guard mallocAndJoin2Dir against size_t overflow#4661
Wingingbump wants to merge 1 commit into
facebook:devfrom
Wingingbump:fix/util-mallocAndJoin2Dir-overflow

Conversation

@Wingingbump
Copy link
Copy Markdown

@Wingingbump Wingingbump commented May 9, 2026

Summary

  • Adds an overflow guard in mallocAndJoin2Dir so dir1Size + dir2Size + 2 cannot wrap size_t and produce an undersized malloc that the following memcpy()s would overrun.
  • Uses the existing CONTROL() pattern, matching how the function already handles allocation failure.

Fixes #4642.

Test plan

  • CI build/test matrix

When `dir1Size + dir2Size + 2` exceeds SIZE_MAX, the sum wraps to a
small value, causing malloc() to allocate an undersized buffer and the
subsequent memcpy() calls to overflow the heap. Add a CONTROL() check
so the overflow is caught before the allocation.

Reported in facebook#4642.
@meta-cla meta-cla Bot added the CLA Signed label May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

这个是整数溢出的问题(Integer Overflow Vulnerability) util.c mallocAndJoin2Dir

1 participant