Skip to content

realpath: don't require read permission on a directory just to confirm a trailing slash#13315

Open
Chaganti-Reddy wants to merge 1 commit into
uutils:mainfrom
Chaganti-Reddy:realpath-path-canonicalization
Open

realpath: don't require read permission on a directory just to confirm a trailing slash#13315
Chaganti-Reddy wants to merge 1 commit into
uutils:mainfrom
Chaganti-Reddy:realpath-path-canonicalization

Conversation

@Chaganti-Reddy

Copy link
Copy Markdown
Contributor

a trailing slash makes realpath assert the target is a directory, but that check was calling read_dir on it, which needs permission to list the directory's contents. GNU only needs a stat-level check there (search permission on the parent, not read on the target itself), so e.g. realpath /root/ works fine as a regular user even though they can't list /root.

swapped it for a metadata().is_dir() check, falling back to read_dir only when it's actually not a directory, so the existing 'Not a directory' error is unchanged.

Fixes #13151

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)

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.

bug(realpath): ///.///../../../root/./ errors out in that path

1 participant