Skip to content

fix: address review comments on core library hardening#1303

Merged
scholarsmate merged 2 commits intofix/core-security-and-qualityfrom
copilot/sub-pr-1302
Mar 6, 2026
Merged

fix: address review comments on core library hardening#1303
scholarsmate merged 2 commits intofix/core-security-and-qualityfrom
copilot/sub-pr-1302

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

Follow-up to #1302 addressing five specific issues raised in code review of the core C/C++ hardening PR.

Changes

encode.c / encode.h

  • Replace assert(src) / assert(dst) with null checks returning 0 in omega_encode_hex2bin
  • Update API doc: dst requires (src_length / 2) + 1 bytes (null-terminated, consistent with bin2hex)

search.cpp

  • Replace assert(0 < pattern_length) with early return nullptr when pattern_length <= 0, consistent with other guards in the same function

edit.cpp

  • omega_edit_undo_last_change: add if (!session_ptr) { return 0; } before accessing session_ptr->models_omega_session_changes_paused(nullptr) returns 0, so a null session would otherwise enter the loop and crash
  • omega_edit_redo_last_undo: same null guard; break out of the redo loop immediately on update_() failure, leaving the failed change in changes_undone so the session isn't advanced further in an error state

filesystem.cpp

  • In omega_util_available_filename, check results of omega_util_dirname, omega_util_basename, and omega_util_file_extension for nullptr before constructing std::string — these can return nullptr for overlong paths, which previously caused UB

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix core C library for security and correctness fix: address review comments on core library hardening Mar 6, 2026
@scholarsmate scholarsmate marked this pull request as ready for review March 6, 2026 21:56
@scholarsmate scholarsmate merged commit d084537 into fix/core-security-and-quality Mar 6, 2026
32 checks passed
@scholarsmate scholarsmate deleted the copilot/sub-pr-1302 branch March 6, 2026 21:56
scholarsmate added a commit that referenced this pull request Mar 7, 2026
#1302)

* fix: harden core C library for security, correctness, and code quality

Security and correctness fixes:
- Fix snprintf buffer overflow in edit.cpp (FILENAME_MAX -> FILENAME_MAX + 1)
- Convert recursive undo/redo to iterative loops to prevent stack overflow
- Add thread_local to static buffers in filesystem.cpp for thread safety
- Add odd-length input validation to omega_encode_hex2bin
- Guard DEBUG define with #ifndef to support conditional compilation
- Remove unsafe mkstemp assert in filesystem.cpp

Design and code quality fixes:
- Replace assert() with proper error returns in all public API functions
  across segment, change, search, viewport, session, check, utility,
  and filesystem modules
- Replace magic number 7 with sizeof(omega_data_t) - 1 in segment.cpp
- Fix DBG macro parenthesization in macros.h
- Rename stl_string_adapter.cpp to stl_string_adaptor.cpp to match header
- Add negative capacity guard in segment creation

Test coverage:
- Add Hex2Bin Odd Length test (7 assertions)
- Add Large Transaction Undo/Redo test (114 assertions)
- Add Null Pointer Safety test for core APIs (53 assertions)
- Add Null Pointer Safety test for utility APIs (14 assertions)
- Add Null Pointer Safety test for filesystem APIs (11 assertions)
- Add Segment Small Data Optimization test (11 assertions)

* fix: address review comments on core library hardening (#1303)

* Initial plan

* fix: address review comments - null checks, error handling, nullptr guards

Co-authored-by: scholarsmate <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: scholarsmate <[email protected]>

* applied fixes

* applied fixes

* optimize undo a bit

* optimize transforms a bit, eliminating ~1/3 of the I/O

* two low-risk performance optimzations

* three additional low-risk performance optimzations

* close testing gaps

* fix: replace dynamic ESM imports with static imports and fix error type assertions in coverageGaps.spec.ts

* fix: use type-agnostic error assertions in coverageGaps.spec.ts

Some client functions reject with string errors (getComputedFileSize,
destroySession) while others reject with Error objects (insert, del).
Use expect(err).to.exist to accept both types.

* fix: harden core C library against remaining review-identified defects (round 4) (#1304)

* Initial plan

* fix: address review comments from PR 1302 review 3907448840

Co-authored-by: scholarsmate <[email protected]>

* fix: improve snprintf checks with explicit result variable and dual condition

Co-authored-by: scholarsmate <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: scholarsmate <[email protected]>

* fix: harden core save and client edit paths

* fix: refresh native server for client tests

* fix: define O_BINARY for non-Windows builds

---------

Co-authored-by: Copilot <[email protected]>
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