Fix: Module error handling, cleanup callback panic handling#48
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request hardens PAM module FFI interactions by improving edge-case error handling and ensuring Rust panics cannot unwind across the C cleanup callback boundary.
Changes:
- Prevents
get_data/get_userfrom returningErr(PAM_SUCCESS)by mapping “success + null pointer” toPAM_SYSTEM_ERR. - Changes invalid-UTF8 username handling to return
PAM_SYSTEM_ERRand documents the behavior. - Wraps the
pam_set_datacleanup callback in robust panic containment logic and adds a regression test for panicking drops.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two module-related fixes:
Err(PAM_SUCCESS)if the library returns aPAM_SUCCESScode and simultaneously hands back a null pointer (for whatever reason). This would lead to an outcome not unlike Unsound unsafe use in PamHandle::get_user #16 (comment) ) (which looked like:failed to get username, error code: PAM_SUCCESS). This PR updates the code to return anPAM_SYSTEM_ERRin this edge case. Also update the "string isn't valid UTF-8" error code toPAM_SYSTEM_ERRand documents it instead of the previously undocumentedPAM_CONV_ERR.a. https://internals.rust-lang.org/t/some-thoughts-on-a-less-slippery-catch-unwind/16902/4
b. Footgun with
catch_unwindwhen catching panic-on-drop types rust-lang/rust#86027