Skip to content

rationalize_path: don't collapse an absolute path to the empty string - #564

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:rationalize-empty-abspath
Oct 14, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:rationalize-empty-abspath

Conversation

@iefa-m

@iefa-m iefa-m commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

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.

@millert millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find, thanks.

@millert
millert merged commit 1ceb330 into sudo-project:main Oct 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants