Repository navigation
🐛 fix(dirs): raise RuntimeError when the passwd home is empty - #757
Merged
Merged
Conversation
When HOME is unset, empty, or relative on POSIX and the password database entry has an empty pw_dir, expand_user() joined the empty string with path[1:] and rooted user directories at / (such as /.config/app on Unix or /Library/Application Support/app on macOS). Check the password database home with _is_absolute() on the explicit passwd fallback path, and reject an empty pw_dir after os.path.expanduser() when HOME is unset and the result is rooted at /.
expand_user read the password database in two branches: one for a set but unusable HOME, and one that undid what expanduser had made of an empty home. With HOME unset now taking the first branch, the second goes away and an empty home is rejected by the same absolute-path check. A relative HOME with an empty passwd home is now tested as well.
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.
On Unix, macOS and iOS, a user whose password database entry has an empty home directory, with
HOMEunset, empty or relative, got user directories rooted at/:/.config/appon Unix, and/Library/Application Support/appon macOS, which is the shared site directory. 🐛 These lookups now raiseRuntimeError, as they already did for a relative password database home and, since #730, for an empty one when root runs withuse_site_for_root. A home of/still resolves to/.config/app.Without an absolute
HOME, the home lookup now always reads the password database entry itself instead of callingos.path.expanduser, which turns an empty home into/. Every result then goes through the existing check that the expanded path is absolute, so an empty home, a relative one and a missing entry fail the same way. An absoluteHOME, an absolute password database home and Windows are unchanged.The example stands in a password database entry with an empty home, since creating such a user needs root:
With the new traceback cut to its last line: