fix: add permission checks to MemMapFs Open/OpenFile#573
Open
veeceey wants to merge 1 commit intospf13:masterfrom
Open
fix: add permission checks to MemMapFs Open/OpenFile#573veeceey wants to merge 1 commit intospf13:masterfrom
veeceey wants to merge 1 commit intospf13:masterfrom
Conversation
MemMapFs was ignoring file permissions entirely -- you could chmod a file to 0 and still open it without error. This made it hard to use MemMapFs for testing code that depends on permission-based behavior. Changes: - Open() now checks read permission bits before returning a file handle - openWrite() now checks write permission bits - Create() sets default permission to 0666, matching os.Create() docs - Stat() uses internal open() to avoid permission checks (matching real stat(2) behavior which doesn't require read permission) - registerWithParent uses 0755 for auto-created parent directories instead of 0, so they remain accessible Fixes spf13#150
Author
Test ResultsFull test suite passes: New test Verified manually:
|
Author
|
hey, any thoughts on this? |
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.
Fixes #150
Right now MemMapFs ignores file permissions completely -- you can chmod a file to 0 and still open/read it without any error. This makes it pretty much impossible to use MemMapFs for testing code that cares about file permissions.
This PR adds basic permission checking:
Open()checks read permission bits (0444) before returning a handleopenWrite()checks write permission bits (0222) before returning a handleCreate()now defaults to 0666 permissions, matching whatos.Create()doesStat()bypasses the permission check (uses internalopen()) since realstat(2)doesn't require read permission eitherregisterWithParentnow get 0755 instead of 0, so they stay accessibleThe permission model is simplified -- it checks any read/write bit being set rather than doing full uid/gid owner/group/other matching. This keeps things straightforward while still catching the common case of chmod 0 or testing read-only vs write-only scenarios.