From c0d3a98fcdd952683714c313bd633ba70d34733f Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Thu, 4 Jul 2019 16:54:42 -0700 Subject: [PATCH] Add warning for chmod -r (fixes #1321) --- src/ShellCheck/Checks/Commands.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index 851d7f2..c95720a 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -94,6 +94,7 @@ commandChecks = [ ,checkSudoRedirect ,checkSudoArgs ,checkSourceArgs + ,checkChmodDashr ] buildCommandMap :: [CommandCheck] -> Map.Map CommandName (Token -> Analysis) @@ -1042,5 +1043,16 @@ checkSourceArgs = CommandCheck (Exactly ".") f "The dot command does not support arguments in sh/dash. Set them as variables." _ -> return () +prop_checkChmodDashr1 = verify checkChmodDashr "chmod -r 0755 dir" +prop_checkChmodDashr2 = verifyNot checkChmodDashr "chmod -R 0755 dir" +prop_checkChmodDashr3 = verifyNot checkChmodDashr "chmod a-r dir" +checkChmodDashr = CommandCheck (Basename "chmod") f + where + f t = mapM_ check $ arguments t + check t = potentially $ do + flag <- getLiteralString t + guard $ flag == "-r" + return $ warn (getId t) 2253 "Use -R to recurse, or explicitly a-r to remove read permissions." + return [] runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])