Skip to content

fix: add bounds checking to prevent buffer overflows in compiler - #917

Open
LuisCastellanos-dev wants to merge 2 commits into
opensourcecobol:developfrom
LuisCastellanos-dev:fix/buffer-overflow-bounds-check
Open

LuisCastellanos-dev wants to merge 2 commits into
opensourcecobol:developfrom
LuisCastellanos-dev:fix/buffer-overflow-bounds-check

Conversation

@LuisCastellanos-dev

Copy link
Copy Markdown

Summary

  • Add buff_end pointer guard in cb_encode_program_id() (cobj/typeck.c) to prevent stack buffer overflow when encoding long UTF-8 PROGRAM-IDs via sprintf()
  • Add strlen() capacity checks before strcat() calls in -D and -I option parsing (cobj/cobj.c) to prevent overflow of cob_define_flags[COB_SMALL_BUFF]

Test plan

  • Compile a COBOL program with a 300+ character UTF-8 PROGRAM-ID — should produce cb_error instead of crashing
  • Pass 50+ -D flags totaling >1024 bytes — should exit with overflow error instead of corrupting stack
  • Normal compilation of existing test suite should pass unchanged

Fixes #912

LuisCastellanos-dev and others added 2 commits October 11, 2026 18:59
- cb_encode_program_id(): add buff_end guard before each sprintf/write
  to prevent stack buffer overflow with long UTF-8 PROGRAM-IDs
- cobj.c -D/-I option parsing: add strlen capacity check before strcat
  to prevent overflow of cob_define_flags[COB_SMALL_BUFF]

Fixes opensourcecobol#912

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UQSdzi4j7ovUnBDWqSDcjF

This branch has not been deployed

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

Security: Buffer overflow in cb_encode_program_id and strcat without bounds check

1 participant