Skip to content

Security Fixes: Critical bug fixes and improved test coverage#3

Merged
viordash merged 9 commits intomasterfrom
fixes
Feb 22, 2026
Merged

Security Fixes: Critical bug fixes and improved test coverage#3
viordash merged 9 commits intomasterfrom
fixes

Conversation

@viordash
Copy link
Copy Markdown
Owner

This PR addresses several critical security and stability issues discovered during code review of the MigrateAnyData library. All fixes include regression tests where applicable.

Key Changes

1. Memory Safety Improvements

Remove dead NULL checks after new operator

  • Standard C++ new throws std::bad_alloc, never returns NULL
  • Removed misleading checks that created false sense of security

Prevent integer overflow in buffer size calculation

  • Changed int to size_t for size calculations
  • Added overflow check before memory allocation

Key files: MigrateAnyData/MigrateAnyData.cpp

2. Input Validation

Add zero division check for stored record size

  • Prevents crash when GetSizeOfCurrentData() returns 0

Add null checks for function pointers

  • Validates MigrateUp, MigrateDown, and onMigrateDataItem before invocation

Key files: MigrateAnyData/MigrateAnyData.cpp

3. String Safety

Ensure null-termination in string field migration macros

  • strncpy doesn't guarantee null-termination when source is longer than buffer
  • Added explicit null-terminator assignment

Key files: MigrateAnyData/MigrateAnyData.h

4. Tests

Added 3 new test cases:

  • TestError_Zero_Record_Size - validates zero size handling
  • TestError_Null_Migrate_Function - validates null function pointer handling
  • TestString_Field_Null_Termination - validates string macro safety

Key files: Tests/Error_Zero_Record_Size.cpp, Tests/Error_Null_Migrate_Function.cpp, Tests/String_Field_Null_Termination.cpp, CMakeLists.txt

5. CI Improvement

Added --output-on-failure to ctest for better debugging in CI.

Key files: .github/workflows/cmake-multi-platform.yml

@viordash viordash merged commit 301cc6e into master Feb 22, 2026
3 checks passed
@viordash viordash deleted the fixes branch February 22, 2026 16:48
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.

1 participant