Skip to content

Conversation

@jserv
Copy link
Contributor

@jserv jserv commented Nov 19, 2025

This implements safer vsnprintf/snprintf with C99 semantics and rigorous bounds checking to eliminate stack buffer overflow vulnerabilities.

  • Add vsnprintf() with proper size parameter and bounds checking
  • Add snprintf() wrapper for formatted string output
  • Remove unsafe sprintf() and vsprintf() functions completely
  • Refactor printf() to use vsnprintf with fixed 256-byte buffer
  • Migrate all application code to snprintf (pipes_small, mqueues, pipes_struct)
  • Add comprehensive libc test suite with 31 tests covering:
    • Basic formatting (%s, %d, %u, %x, %p, %c, %%)
    • Edge cases (size=0, size=1, truncation)
    • C99 semantics (return values, null termination)
    • Buffer boundary protection
    • ISR safety (reentrancy, no malloc, bounded execution)

Summary by cubic

Replaced unsafe formatting with bounded snprintf/vsnprintf (C99) to fix stack buffer overflows and guarantee null-termination. Refactored printf and app code; added a libc test suite for edge cases and truncation.

  • Bug Fixes

    • Eliminates stack buffer overruns via bounds-aware writes.
    • Enforces C99 return values and null-termination when size > 0.
    • Reentrant and ISR-safe; no dynamic allocation.
  • Refactors

    • Added vsnprintf/snprintf; removed sprintf/vsprintf.
    • printf now uses vsnprintf with a fixed 256-byte buffer.
    • Migrated apps to snprintf (pipes_small, mqueues, pipes_struct); added test_libc and Makefile entry.

Written for commit 2137698. Summary will update automatically on new commits.

This implements safer vsnprintf/snprintf with C99 semantics and rigorous
bounds checking to eliminate stack buffer overflow vulnerabilities.
- Add vsnprintf() with proper size parameter and bounds checking
- Add snprintf() wrapper for formatted string output
- Remove unsafe sprintf() and vsprintf() functions completely
- Refactor printf() to use vsnprintf with fixed 256-byte buffer
- Migrate all application code to snprintf (pipes_small, mqueues, pipes_struct)
- Add comprehensive libc test suite with 31 tests covering:
  * Basic formatting (%s, %d, %u, %x, %p, %c, %%)
  * Edge cases (size=0, size=1, truncation)
  * C99 semantics (return values, null termination)
  * Buffer boundary protection
  * ISR safety (reentrancy, no malloc, bounded execution)
@github-actions
Copy link

Linmo CI Test Results

Overall Status: ✅ passed
Timestamp: 2025-11-19T16:03:12+00:00

Toolchain Results

Toolchain Build Crash Test Functional
GNU ✅ passed ✅ passed ✅ passed
LLVM ✅ passed ⏭️ skipped ⏭️ skipped

Application Tests

App GNU LLVM
cond ✅ passed ⏭️ skipped
coop ✅ passed ⏭️ skipped
cpubench ✅ passed ⏭️ skipped
echo ✅ passed ⏭️ skipped
hello ✅ passed ⏭️ skipped
mqueues ✅ passed ⏭️ skipped
mutex ✅ passed ⏭️ skipped
pipes ✅ passed ⏭️ skipped
pipes_small ✅ passed ⏭️ skipped
pipes_struct ✅ passed ⏭️ skipped
prodcons ✅ passed ⏭️ skipped
progress ✅ passed ⏭️ skipped
rtsched ✅ passed ⏭️ skipped
semaphore ✅ passed ⏭️ skipped
suspend ✅ passed ⏭️ skipped
test64 ✅ passed ⏭️ skipped
test_libc ✅ passed ⏭️ skipped
timer ✅ passed ⏭️ skipped
timer_kill ✅ passed ⏭️ skipped

Functional Test Details

Test GNU LLVM
mutex:data_consistency ✅ passed ⏭️ skipped
mutex:fairness ✅ passed ⏭️ skipped
mutex:mutual_exclusion ✅ passed ⏭️ skipped
mutex:overall ✅ passed ⏭️ skipped
semaphore:all_tests_passed! ✅ passed ⏭️ skipped

Report generated from test-summary.toml

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

@jserv jserv merged commit 0ce5a6c into main Nov 19, 2025
4 checks passed
@jserv jserv deleted the fix-buffer-overflow branch November 19, 2025 16:18
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