[bug #66374] Permissions errors from unnecessary attemp to read symlink targets

Adam Dinwoodie <[email protected]>
Newsgroups gmane.comp.gnu.findutils.bugs
Message-ID <[email protected]>
URL:
  <https://savannah.gnu.org/bugs/?66374>

                 Summary: Permissions errors from unnecessary attemp to read
symlink targets
                   Group: findutils
               Submitter: me_and
               Submitted: Thu 24 Oct 2024 10:28:00 AM UTC
                Category: find
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: None
           Fixed Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Thu 24 Oct 2024 10:28:00 AM UTC By: Adam Dinwoodie <me_and>
Consider the following command:


find "$dir" -type l \! -lname "$path" -xtype l


I've been trying to use this to find broken symlinks, but using the `\! -lname
"$path"` part to exclude symlinks where the target is in a directory I do not
have access to so the `-xtype` test cannot be checked. However, even when the
`-lname` test succeeds, `find` produces a "Permission denied" error.

Minimal repro below, where everything works as expected until the final `find`
command, which I would have expected to produce the same output as the
previous command.


$ mkdir demo
$ sudo chown root:root demo
$ sudo chmod 700 demo
$ ln -s demo/file symlink
$ find symlink -print
symlink
$ find symlink \! -lname '*/file' -print
$ find symlink \! -lname '*/file' -xtype l -print
find: ‘symlink’: Permission denied


There's a more comprehensive and commented repro in the attached Bash script.
Changing the optimisation level seems to make no difference; if you specify
-O<n> arguments to the attached demo script then they'll be passed through to
the `find` calls.

`find --version` output below:


find (GNU findutils) 4.9.0
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS(FTS_CWDFD)
CBO(level=2)








    _______________________________________________________
File Attachments:


-------------------------------------------------------
Name: demo.sh  Size: 3KiB
<https://file.savannah.gnu.org/file/demo.sh?file_id=56569>

    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-fe88ab40cb3eb3bf250224c46c17b33c85ea0249.tar.gz

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?66374>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCZxohNAAKCRCqLAuaBUf3
ToHdAP9WCHB7H95Hj5CseKmvsSeiyDtGmsX7XVIjcoIqEuF1rgD8D5NWjy6uM4a4
R0a/a76/cyx3z3Y6ci3Qq28uHPeXwQ4=
=vTxG
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.