[Toybox] rm -rf doesn't chmod high enough

Isaac Dunham ibid.ag at gmail.com
Thu Sep 18 09:42:31 PDT 2014


rm -rf needs to chmod directories to u+rwx, because directories need +x
to search.
(Fixes messages about not being able to delete directories when running 
make test).

--
A trickier bug is that rm -r dir will skip dir, saying 
"rm: dir: is a directory"
I guess the fix involves rm -r calling rmdir instead of unlink.

Thanks,
Isaac Dunham

-------------- next part --------------
diff --git a/toys/posix/rm.c b/toys/posix/rm.c
index 6c98404..9561a67 100644
--- a/toys/posix/rm.c
+++ b/toys/posix/rm.c
@@ -49,7 +49,7 @@ static int do_rm(struct dirtree *try)
   if (dir) {
     // Handle chmod 000 directories when -f
     if (faccessat(fd, try->name, R_OK, AT_SYMLINK_NOFOLLOW)) {
-      if (toys.optflags & FLAG_f) wfchmodat(fd, try->name, 0600);
+      if (toys.optflags & FLAG_f) wfchmodat(fd, try->name, 0700);
       else goto skip;
     }
     if (!try->again) return DIRTREE_COMEAGAIN;


More information about the Toybox mailing list