Repository navigation
rationalize_path: don't collapse an absolute path to the empty string - #564
Merged
Merged
Conversation
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.
rationalize_path collapses an absolute path that reduces to the root, such as /. or /usr/..//., to the empty string instead of /. The /./ and /. removal does memmove(cp, cp + 2, ...), and when cp is sitting on the leading slash with nothing after the dot that also eats the root slash and leaves "". canonicalize_edit_args runs rationalize_path over every sudoedit argument, so
sudoedit /.rewrites the argument to an empty string before it is matched and opened.Restore the slash when collapsing /. at the start of an absolute path would otherwise empty it, so an absolute path never turns into a relative or empty one. Keeping the check inside rationalize_path means both callers, the sudoedit canonicalisation and find_path, get the corrected result. The regress test gains the /., //., /.//. and /usr/..//. cases, which all yield "" before this change and / after.