$ grep -rP "(?!(?=(?'a'[\s\S]*))(?'b'\/usr(?=\k'a'\z)|(?<=(?=x^|(?&b))[\s\S])))\/bin\/(?!(sh|ksh|zsh|bsh|bash|dash|mount|umount|echo|true|false|ls|rm|mv|ln|cat))" /usr/bin
doesn't really show any objectionable binaries being referred to via /bin (I count those I excluded in the negative lookahead as certainly non-objectionable).(I used the variable-length negative lookbehind [1] because I wanted to reduce false positives, but just scrolling through the results ended up being easier)
[1] http://www.drregex.com/2019/02/variable-length-lookbehinds-a...
Alternatively, a simple
grep --binary-files=text -rP '(?<!/usr)/bin/(?!sh|ksh|zsh|bsh|bash|dash|mount|umount|echo|true|false|ls|rm|mv|ln|cat)' /usr/bin
to also include binary files does the job as well.In the case of symlinked directories we have:
- the binary lives in /usr/bin/python3
- /bin is a symlink to /usr/bin
- /bin/python3 therefore refers to /usr/bin/python3
We can use either /usr/bin/python3 or /bin/python3.In the case of a link farm we have:
- the binary lives in /usr/bin/python3
- /bin/python3 is a symlink to /usr/bin/python3
Again we can use either /usr/bin/python3 or /bin/python3.As far as I can see, both methods allow insufficiently careful developers to hardcode the wrong paths. What am I missing?
You don't symlink everything in /usr/bin to /bin, just "all regular files that have traditionally been in /bin" (per the article).
python3 has not traditionally been in /bin, so /bin/python3 would not be linked.
Also, I don't see how a folder filled with symlinks would prevent the problem that are you talking.