chown+chgrp+chmod: Fix handling of preserve root flag and error messages#6042
Conversation
|
GNU testsuite comparison: |
4bc6b83 to
956cf69
Compare
|
Changes since last push:
|
|
GNU testsuite comparison: |
tertsdiepraam
left a comment
There was a problem hiding this comment.
Alright, please check that I understand correctly. Here's what I got from this:
We need to know whether symlinks will be dereferenced on the path to know how to check for root. Dereferencing happens if either the setting for dereferencing is passed or if the / is at the end, so that we need to enter the directory and to do that need to dereference.
Does that make sense? If so, could you add that last part in a comment somewhere. It took me a while to understand :)
I also wonder if these path checks are the right way to do it. Maybe there's some other way to check this? It all feels inherently finnicky.
One of the GNU tests checks for the exact error message.
956cf69 to
31e6fa7
Compare
|
Changes since last push:
|
|
Nope, wait, I got something wrong with the quoting. |
…message This is explicitly tested in the GNU tests.
This function is by necessity ill-defined: Depending on the context, '..' is either the logical parent directory, sometimes the physical parent directory. This function can only work for the latter case, in which case `Path::canonicalize` is often a better approach.
31e6fa7 to
d25d994
Compare
|
Changes since last push:
|
|
GNU testsuite comparison: |
|
well done :) |
This makes the GNU
preserve-root.logtest green.In particular:
Path::is_dir()completely ignores whether a given argument has a trailing slash or not, but that is the criterion that GNU (and many other tools) apparently uses to decide whether the path points "at" or "into" a directory. (See below for demonstration.)chmodsimply forgot to output its own name in one place.Additional notes:
resolve_relative_pathsuperfluous. This function is by necessity ill-defined: Depending on the context,..is either the logical parent directory, sometimes the physical parent directory. This function can only work for the latter case, in which casePath::canonicalizeis often a better approach.chown -R -Land the attacker can quickly inject a directory and replace it with a symlink to/, then--preserve-rootdoes not trigger. However, in this scenario the attacker could probably just as well create a handful of symlinks, one for each directory in/, for the same effect. So this is not a vulnerability, just an unavoidable bug.)Path::is_dirdemoproduces