diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index e65dc68..b2d9ec7 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -607,9 +607,11 @@ prop_checkInteractiveSu1 = verify checkInteractiveSu "su; rm file; su $USER" prop_checkInteractiveSu2 = verify checkInteractiveSu "su foo; something; exit" prop_checkInteractiveSu3 = verifyNot checkInteractiveSu "echo rm | su foo" prop_checkInteractiveSu4 = verifyNot checkInteractiveSu "su root < script" +prop_checkInteractiveSu5 = verify checkInteractiveSu "su -c something" +prop_checkInteractiveSu6 = verify checkInteractiveSu "su --command=something" checkInteractiveSu = CommandCheck (Basename "su") f where - f cmd = when (length (arguments cmd) <= 1) $ do + f cmd = when (noCommandArgPresent (arguments cmd)) $ do path <- getPathM cmd when (all undirected path) $ info (getId cmd) 2117 @@ -620,6 +622,9 @@ checkInteractiveSu = CommandCheck (Basename "su") f undirected (T_Redirecting _ (_:_) _) = False undirected _ = True + noCommandArgPresent = not . any isCommandArg . map (getLiteralStringDef "_") + isCommandArg arg = arg == "-c" && "--command=" `isPrefixOf` arg + -- This is hard to get right without properly parsing ssh args prop_checkSshCmdStr1 = verify checkSshCommandString "ssh host \"echo $PS1\""