From 70ab2dfb923e98fc1b0af27ec98efd0220fe6de6 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 28 Jan 2020 21:49:52 -0600 Subject: David Legault complained that dir/.* tells rm to delete dir/.. and we'd do it. --- toys/posix/rm.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'toys/posix') diff --git a/toys/posix/rm.c b/toys/posix/rm.c index 2a6bc282..eec586c5 100644 --- a/toys/posix/rm.c +++ b/toys/posix/rm.c @@ -99,6 +99,11 @@ void rm_main(void) error_msg("rm /. if you mean it"); continue; } + // "rm dir/.*" can expand to include .. which generally isn't what you want + if (!strcmp("..", basename(*s))) { + error_msg("bad path %s", *s); + continue; + } // Files that already don't exist aren't errors for -f, so try a quick // unlink now to see if it succeeds or reports that it didn't exist. -- cgit v1.2.3