Allow 'su --command=something'

Previously, 'su --command=something' would result in SC2117 although
it is the official long version of 'su -c something'.
This commit is contained in:
Pascal Wittmann 2022-07-07 23:33:43 +02:00
commit a0c2fa4b2b

View file

@ -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\""