Skip to content

rmdir: GNU incompatible handling of symlinks with multiple trailing slashes #9980

Closed

Description

@sylvestre

Component

rmdir

Description

Current implementation of rmdir strips only a single trailing / before checking is_symlink(). For inputs like link// or link///, the derived no_slash path still ends with /.

let no_slash: &Path = OsStr::from_bytes(&bytes[..bytes.len() - 1]).as_ref();

On Linux, a trailing slash on a pathname whose final component is a symlink changes pathname resolution semantics.

Test / Reproduction Steps

core_sbx$ cat rmdir_test.sh 
#!/bin/bash

rm -rf ./uutils-rmdir-test
mkdir -p ./uutils-rmdir-test/target
ln -s ./uutils-rmdir-test/target ./uutils-rmdir-test/link

echo "GNU"
cd ./uutils-rmdir-test && /bin/rmdir link/
cd ../
cd ./uutils-rmdir-test && /bin/rmdir link//
cd ../
cd ./uutils-rmdir-test && /bin/rmdir link///
cd ../

rm -rf ./uutils-rmdir-test
mkdir -p ./uutils-rmdir-test/target
ln -s ./uutils-rmdir-test/target ./uutils-rmdir-test/link

echo "uutils"
cd ./uutils-rmdir-test && ../../target/release/rmdir link/ 2>&1
cd ../
cd ./uutils-rmdir-test && ../../target/release/rmdir link// 2>&1
cd ../
cd ./uutils-rmdir-test && ../../target/release/rmdir link/// 2>&1
cd ../
core_sbx$
core_sbx$ bash rmdir_test.sh
GNU
rmdir: failed to remove 'link/': Symbolic link not followed
rmdir: failed to remove 'link//': Symbolic link not followed
rmdir: failed to remove 'link///': Symbolic link not followed
uutils
no_slash? "link"
../../target/release/rmdir: failed to remove 'link/': Symbolic link not followed
no_slash? "link/"
../../target/release/rmdir: failed to remove 'link//': Not a directory
no_slash? "link//"
../../target/release/rmdir: failed to remove 'link///': Not a directory

Impact

For symlink operands with multiple trailing slashes, uutils may emit a different diagnostic than GNU.
It can affect scripts that rely on diagnostic text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions