Reject path-like locale names in Locale.load - #1031
Open
Sharadhi-v98 wants to merge 1 commit into
Open
Sharadhi-v98 wants to merge 1 commit into
Sharadhi-v98 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Locale.load joins the locale name onto the locales package directory to check that it exists, then imports it as a submodule. The name comes straight from the locale argument of format, diff_for_humans, in_words, from_format and set_locale, and nothing checks that it is a plain name. An absolute path replaces the package directory in the join and ../ walks out of it, so the existence check runs against whatever path the caller supplied. When that path exists the import fails with ModuleNotFoundError instead of the ValueError an unknown locale raises: set_locale("/etc/passwd") gives ModuleNotFoundError while set_locale("/etc/nope") gives ValueError, which tells the caller whether the path is there. A name that is not a plain locale identifier is now rejected with the usual ValueError before the filesystem is touched.