fix: Double-close fd in ManifestWatcher deinit + validation consistency#113
fix: Double-close fd in ManifestWatcher deinit + validation consistency#1132witstudios merged 3 commits intomainfrom
Conversation
ManifestWatcher.deinit closed the file descriptor directly AND via the source's cancel handler, risking closing an unrelated fd that reused the same number. Also synchronized isWatching to match the class's queue invariant, and fixed validate_name to consistently use the trimmed input. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughTwo minor logic improvements across macOS and Rust codebases: a thread-safety enhancement to the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/pu-core/src/validation.rs (1)
37-48: Consider adding tests for whitespace-padded malicious inputs.While the current tests cover core cases, explicit tests for whitespace-padded inputs would strengthen confidence in the trimmed validation behavior:
#[test] fn given_whitespace_padded_traversal_should_reject() { assert!(validate_name(" ../evil").is_err()); assert!(validate_name("foo/../bar ").is_err()); assert!(validate_name(" /root").is_err()); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/pu-core/src/validation.rs` around lines 37 - 48, Add unit tests exercising validate_name with whitespace-padded inputs to ensure trimming before validation rejects malicious values; create a test (e.g., given_whitespace_padded_traversal_should_reject) that calls validate_name with strings like " ../evil", "foo/../bar " and " /root" and asserts is_err() for each, reusing the existing test style and assertion pattern around validate_name to confirm trimmed traversal and slash cases are rejected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/pu-core/src/validation.rs`:
- Around line 37-48: Add unit tests exercising validate_name with
whitespace-padded inputs to ensure trimming before validation rejects malicious
values; create a test (e.g., given_whitespace_padded_traversal_should_reject)
that calls validate_name with strings like " ../evil", "foo/../bar " and "
/root" and asserts is_err() for each, reusing the existing test style and
assertion pattern around validate_name to confirm trimmed traversal and slash
cases are rejected.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 52f31f54-2192-499d-bc0d-38cbcef5b607
📒 Files selected for processing (2)
apps/purepoint-macos/purepoint-macos/Services/ManifestWatcher.swiftcrates/pu-core/src/validation.rs
Propagate print_response Results in bench/play commands, fix missing .unwrap() in test, and add whitespace-padded input tests per CodeRabbit review suggestion. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Addressed the CodeRabbit nitpick — added Also fixed 3 unused All local validation passes (clippy + tests). |
Summary
deinitclosed the file descriptor directly AND via the dispatch source's cancel handler. After the first close, the fd number can be reused by anotheropen()call, and the second close would silently close a completely unrelated file descriptor belonging to another subsystem.isWatchingreadsourcewithout queue synchronization, violating the class's own invariant that all mutable state is accessed on its serial queue.trimmedbut path traversal checks used the original untrimmedname. Now consistently usestrimmedfor all checks.Test plan
cargo test -p pu-core -- validation)🤖 Generated with Claude Code
Summary by CodeRabbit