Skip to content

chown: -h on symlink to directory operates on link, not target - #12522

Merged
sylvestre merged 2 commits into
uutils:mainfrom
rossilor95:chown-fix-h-symlink-to-dir
May 30, 2026
Merged

chown: -h on symlink to directory operates on link, not target#12522
sylvestre merged 2 commits into
uutils:mainfrom
rossilor95:chown-fix-h-symlink-to-dir

Conversation

@rossilor95

@rossilor95 rossilor95 commented May 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #11887

chown -h on a symlink-to-directory chowned the target instead of the link. The Linux fast path used Path::is_dir(), which resolves symlinks and routed the call into the directory-traversal branch.

Switch to Metadata::is_dir() on the already-lstat'd metadata so the --no-dereference contract is preserved. Added regression test test_chown_no_dereference_symlink_to_dir that creates a symlink to a directory, runs chown --no-dereference, and asserts via ctime that the syscall touched the symlink's inode (link's ctime advances) and not the target's (directory's ctime is unchanged). Confirmed the test fails on the unfixed code and passes with the fix.

Repro (from #11887)

$ chown -h nobody root                 # symlink: root -> /root
$ ls -ld /root root
drwx------ nobody root  /root          # ← bug: target chowned
lrwxrwxrwx root   root  root -> /root  # ← bug: link untouched

# GNU does the opposite
$ gnuchown -h nobody root
drwx------ root   root  /root
lrwxrwxrwx nobody root  root -> /root

@github-actions

github-actions Bot commented May 30, 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)

@sylvestre

Copy link
Copy Markdown
Contributor

some jobs are failing

@rossilor95
rossilor95 force-pushed the chown-fix-h-symlink-to-dir branch from d94fc78 to d1d887e Compare May 30, 2026 09:02
@rossilor95

rossilor95 commented May 30, 2026

Copy link
Copy Markdown
Contributor Author

some jobs are failing

I solved the style issue (my bad, forgot to run cargo fmt before committing 😅).

About Open BSD/Tests, seems to be failing with the same error for at least another PR, error: linking with cc failed: exit status: 1. Any ideas?

@sylvestre
sylvestre merged commit ed15a26 into uutils:main May 30, 2026
169 of 170 checks passed
@xtqqczze

Copy link
Copy Markdown
Contributor

test_chown_no_dereference_symlink_to_dir was failing on merge: https://github.com/uutils/coreutils/actions/runs/26679895315/job/78638347716#step:3:6091

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.

chown -h doesn't work when the target is a directory

3 participants