Skip to content

fix: Address local memory boundaries and buffer constraints - #184

Open
doomedraven wants to merge 5 commits into
kevoreilly:capemonfrom
doomedraven:opt/fix-bounds
Open

doomedraven wants to merge 5 commits into
kevoreilly:capemonfrom
doomedraven:opt/fix-bounds

Conversation

@doomedraven

Copy link
Copy Markdown
Contributor

Resolves unsigned underflow allocations hitting snprintf routines and expands hardcoded local stack matrices breaking deep module hooking structures.

@kevoreilly

Copy link
Copy Markdown
Owner

I note this goes in the opposite direction to #153 and swaps a stack-based buffer for an allocation.

@doomedraven

Copy link
Copy Markdown
Contributor Author

will check in a bit

doomedraven and others added 3 commits September 4, 2026 15:55
Centralize the shared output buffer limit in `hooking.h` and harden exception/watchdog logging against overruns. This replaces unsafe `snprintf`/`strcat` patterns with bounded `_snprintf_s` calls, adds a NULL check after `malloc`, and guards all log appends so long stack traces and severe faults are truncated safely instead of corrupting memory.
- In unhook.c (_watchdog_thread): use stack-allocated buffer (char msg[1024]) instead of heap allocation, strictly adhering to the SBO pattern from PR kevoreilly#153
- In capemon.c (capemon_exception_handler): fix sizeof(msg) pointer underflow calculation by using explicit remaining buffer capacity with _snprintf_s and _TRUNCATE
- Drop global WIDE_STRING_LIMIT definition from hooking.h
@doomedraven

Copy link
Copy Markdown
Contributor Author

Good catch @kevoreilly. Refactored to preserve the stack-allocation / SBO pattern from #153:

  1. Reverted _watchdog_thread in unhook.c back to a stack-allocated buffer (char msg[1024]), completely eliminating the heap allocation. Bounds and truncation are handled via _snprintf_s(msg + len, sizeof(msg) - len, _TRUNCATE, ...).
  2. Removed the WIDE_STRING_LIMIT macro from hooking.h.
  3. Kept the sizeof(msg) pointer underflow fixes in capemon_exception_handler (capemon.c) using explicit remaining buffer capacity checks.
  4. Synchronized with latest upstream/capemon.

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.

2 participants