Skip to content

Conversation

@naftaly
Copy link
Collaborator

@naftaly naftaly commented Dec 3, 2025

Note

Fixes #724

  • Add null safety checks for memory parameters before use
  • Apply file protection NSFileProtectionCompleteUntilFirstUserAuthentication to memory files so they remain accessible while the device is locked
  • Add safe string copy utility function with proper bounds checking
  • Improve buffer handling in memory-mapped file operations
  • Added new tests to fill gaps

@naftaly naftaly marked this pull request as ready for review December 3, 2025 17:17
Copilot finished reviewing on behalf of naftaly December 3, 2025 17:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances memory monitor safety and robustness by adding null safety checks, improving file handling, and providing proper cleanup mechanisms. The changes address potential edge cases in memory-mapped file operations and ensure the monitor handles enable/disable cycles gracefully without leaking resources.

Key changes:

  • Fixed a bug where ksfu_mmap returned MAP_FAILED instead of NULL on error
  • Added ksfu_munmap wrapper for consistent memory unmapping with null pointer handling
  • Improved timestamp validation to reject future timestamps (corrupted data detection)
  • Added file protection attributes to ensure memory files remain accessible while device is locked

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Sources/KSCrashRecordingCore/KSFileUtils.c Fixed mmap error path bug and implemented ksfu_munmap wrapper with null safety
Sources/KSCrashRecordingCore/include/KSFileUtils.h Added ksfu_munmap function declaration and updated documentation
Sources/KSCrashRecording/Monitors/KSCrashMonitor_Memory.m Added null checks, improved cleanup in setEnabled, applied file protection, fixed timestamp validation, corrected header comment
Tests/KSCrashRecordingTests/KSCrashMonitor_Memory_Tests.m Added tests for rapid enable/disable cycles and edge case handling
Tests/KSCrashRecordingCoreTests/KSFileUtils_Tests.m Added comprehensive memory mapping tests including null pointer handling and round-trip validation

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.

EXC_BAD_ACCESS in _ks_memory_update_from_app_memory

2 participants