@@ -99,8 +99,6 @@ commandChecks = [
9999 ,checkMvArguments, checkCpArguments, checkLnArguments
100100 ,checkFindRedirections
101101 ,checkReadExpansions
102- ,checkSudoRedirect
103- ,checkSudoArgs
104102 ,checkSourceArgs
105103 ,checkChmodDashr
106104 ,checkXargsDashi
@@ -111,6 +109,8 @@ commandChecks = [
111109 ++ map checkMaskedReturns declaringCommands
112110 ++ map checkMultipleDeclaring declaringCommands
113111 ++ map checkBackreferencingDeclaration declaringCommands
112+ ++ map checkSudoArgs privilegeElevationCommands
113+ ++ map checkSudoRedirect privilegeElevationCommands
114114
115115
116116optionalChecks = map fst optionalCommandChecks
@@ -1199,14 +1199,14 @@ prop_checkWhich = verify checkWhich "which '.+'"
11991199checkWhich = CommandCheck (Basename " which" ) $
12001200 \ t -> info (getId $ getCommandTokenOrThis t) 2230 " 'which' is non-standard. Use builtin 'command -v' instead."
12011201
1202- prop_checkSudoRedirect1 = verify checkSudoRedirect " sudo echo 3 > /proc/file"
1203- prop_checkSudoRedirect2 = verify checkSudoRedirect " sudo cmd < input"
1204- prop_checkSudoRedirect3 = verify checkSudoRedirect " sudo cmd >> file"
1205- prop_checkSudoRedirect4 = verify checkSudoRedirect " sudo cmd &> file"
1206- prop_checkSudoRedirect5 = verifyNot checkSudoRedirect " sudo cmd 2>&1"
1207- prop_checkSudoRedirect6 = verifyNot checkSudoRedirect " sudo cmd 2> log"
1208- prop_checkSudoRedirect7 = verifyNot checkSudoRedirect " sudo cmd > /dev/null 2>&1"
1209- checkSudoRedirect = CommandCheck (Basename " sudo " ) f
1202+ prop_checkSudoRedirect1 = verify ( checkSudoRedirect " sudo " ) " sudo echo 3 > /proc/file"
1203+ prop_checkSudoRedirect2 = verify ( checkSudoRedirect " doas " ) " doas cmd < input"
1204+ prop_checkSudoRedirect3 = verify ( checkSudoRedirect " run0 " ) " run0 cmd >> file"
1205+ prop_checkSudoRedirect4 = verify ( checkSudoRedirect " sudo " ) " sudo cmd &> file"
1206+ prop_checkSudoRedirect5 = verifyNot ( checkSudoRedirect " sudo " ) " sudo cmd 2>&1"
1207+ prop_checkSudoRedirect6 = verifyNot ( checkSudoRedirect " doas " ) " doas cmd 2> log"
1208+ prop_checkSudoRedirect7 = verifyNot ( checkSudoRedirect " run0 " ) " run0 cmd > /dev/null 2>&1"
1209+ checkSudoRedirect cmd = CommandCheck (Basename cmd ) f
12101210 where
12111211 f t = do
12121212 t_redir <- getClosestCommandM t
@@ -1218,32 +1218,32 @@ checkSudoRedirect = CommandCheck (Basename "sudo") f
12181218 case op of
12191219 T_Less _ ->
12201220 info (getId op) 2024
1221- " sudo doesn't affect redirects. Use sudo cat file | .."
1221+ " sudo/doas/run0 doesn't affect redirects. Use sudo cat file | .."
12221222 T_Greater _ ->
12231223 warn (getId op) 2024
1224- " sudo doesn't affect redirects. Use ..| sudo tee file"
1224+ " sudo/doas/run0 doesn't affect redirects. Use ..| sudo tee file"
12251225 T_DGREAT _ ->
12261226 warn (getId op) 2024
1227- " sudo doesn't affect redirects. Use .. | sudo tee -a file"
1227+ " sudo/doas/run0 doesn't affect redirects. Use .. | sudo tee -a file"
12281228 _ -> return ()
12291229 warnAbout _ = return ()
12301230 special file = concat (oversimplify file) == " /dev/null"
12311231
1232- prop_checkSudoArgs1 = verify checkSudoArgs " sudo cd /root"
1233- prop_checkSudoArgs2 = verify checkSudoArgs " sudo export x=3"
1234- prop_checkSudoArgs3 = verifyNot checkSudoArgs " sudo ls /usr/local/protected"
1235- prop_checkSudoArgs4 = verifyNot checkSudoArgs " sudo ls && export x=3"
1236- prop_checkSudoArgs5 = verifyNot checkSudoArgs " sudo echo ls"
1237- prop_checkSudoArgs6 = verifyNot checkSudoArgs " sudo -n -u export ls"
1238- prop_checkSudoArgs7 = verifyNot checkSudoArgs " sudo docker export foo"
1239- checkSudoArgs = CommandCheck (Basename " sudo " ) f
1232+ prop_checkSudoArgs1 = verify ( checkSudoArgs " sudo " ) " sudo cd /root"
1233+ prop_checkSudoArgs2 = verify ( checkSudoArgs " run0 " ) " run0 export x=3"
1234+ prop_checkSudoArgs3 = verifyNot ( checkSudoArgs " sudo " ) " sudo ls /usr/local/protected"
1235+ prop_checkSudoArgs4 = verifyNot ( checkSudoArgs " doas " ) " doas ls && export x=3"
1236+ prop_checkSudoArgs5 = verifyNot ( checkSudoArgs " sudo " ) " sudo echo ls"
1237+ prop_checkSudoArgs6 = verifyNot ( checkSudoArgs " sudo " ) " sudo -n -u export ls"
1238+ prop_checkSudoArgs7 = verifyNot ( checkSudoArgs " sudo " ) " sudo docker export foo"
1239+ checkSudoArgs cmd = CommandCheck (Basename cmd ) f
12401240 where
12411241 f t = sequence_ $ do
12421242 opts <- parseOpts $ arguments t
12431243 (_,(commandArg, _)) <- find (null . fst ) opts
12441244 command <- getLiteralString commandArg
12451245 guard $ command `elem` builtins
1246- return $ warn (getId t) 2232 $ " Can't use sudo with builtins like " ++ command ++ " . Did you want sudo sh -c .. instead?"
1246+ return $ warn (getId t) 2232 $ " Can't use sudo/doas/run0 with builtins like " ++ command ++ " . Did you want sudo/doas/run0 sh -c .. instead?"
12471247 builtins = [ " cd" , " command" , " declare" , " eval" , " exec" , " exit" , " export" , " hash" , " history" , " local" , " popd" , " pushd" , " read" , " readonly" , " return" , " set" , " source" , " trap" , " type" , " typeset" , " ulimit" , " umask" , " unset" , " wait" ]
12481248 -- This mess is why ShellCheck prefers not to know.
12491249 parseOpts = getBsdOpts " vAknSbEHPa:g:h:p:u:c:T:r:"
0 commit comments