aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-03-15 17:08:58 -0700
committerRob Landley <rob@landley.net>2021-03-15 21:57:01 -0500
commite63c9967423b5b9c6fc48d2b31a04e3c030bc16a (patch)
tree0646d07f9b868ba62b97b1709d6739527584b897
parent8e9d7aaa838ed58b7b354a3b378cda1bd84f8dc5 (diff)
downloadtoybox-e63c9967423b5b9c6fc48d2b31a04e3c030bc16a.tar.gz
chmod: fix +X.
I broke this when I added the masking out of the S_IFMT bits for macOS, because string_to_mode needs the full mode with those extra bits, specifically so that it can recognize directories for +X to work. I've duplicated chtest rather than change chtest to explicitly set the modes to 000 before running the given chmod command because I didn't want to touch *all* the tests and obscure the addition of just one.
-rwxr-xr-xtests/chmod.test5
-rw-r--r--toys/posix/chmod.c2
2 files changed, 6 insertions, 1 deletions
diff --git a/tests/chmod.test b/tests/chmod.test
index cd4f8100..6c4de0c0 100755
--- a/tests/chmod.test
+++ b/tests/chmod.test
@@ -115,6 +115,11 @@ unset SKIP
chtest +t "drwxr-xr-t\n-rw-r--r-T\n"
chtest a=r+w+x "drwxrwxrwx\n-rwxrwxrwx\n"
+# (chtest starts off with a directory that's +x...)
+testing "+X" \
+ "mkdir -m 000 Xd && touch Xf && chmod +X Xd Xf && ls -ld Xd Xf | cut -d' ' -f 1" \
+ "d--x--x--x\n-rw-r--r--\n" "" ""
+
mkdir foo
ln -s bar foo/baz
# If you explicitly ask us, we'll try (and fail) to chmod a symlink.
diff --git a/toys/posix/chmod.c b/toys/posix/chmod.c
index 2cdda951..ef74c4fa 100644
--- a/toys/posix/chmod.c
+++ b/toys/posix/chmod.c
@@ -50,7 +50,7 @@ static int do_chmod(struct dirtree *try)
// symlinks mentioned directly as arguments. We'll fail, of course,
// but that's what you asked for in that case.
} else {
- mode = string_to_mode(TT.mode, try->st.st_mode & ~S_IFMT);
+ mode = string_to_mode(TT.mode, try->st.st_mode) & ~S_IFMT;
if (FLAG(v)) {
char *s = dirtree_path(try, 0);