From a0c2fa4b2bbbf251ea2fd2f10763f546e7d45cf4 Mon Sep 17 00:00:00 2001 From: Pascal Wittmann Date: Thu, 7 Jul 2022 23:33:43 +0200 Subject: [PATCH] Allow 'su --command=something' Previously, 'su --command=something' would result in SC2117 although it is the official long version of 'su -c something'. --- src/ShellCheck/Checks/Commands.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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\""