Also check nested ifs for ssh/ffmpeg in read loops
This commit is contained in:
parent
d830a36bc8
commit
133c779701
|
@ -2277,6 +2277,7 @@ prop_checkWhileReadPitfalls3 = verifyNot checkWhileReadPitfalls "while true; do
|
||||||
prop_checkWhileReadPitfalls4 = verifyNot checkWhileReadPitfalls "while read foo; do ssh $foo hostname < /dev/null; done"
|
prop_checkWhileReadPitfalls4 = verifyNot checkWhileReadPitfalls "while read foo; do ssh $foo hostname < /dev/null; done"
|
||||||
prop_checkWhileReadPitfalls5 = verifyNot checkWhileReadPitfalls "while read foo; do echo ls | ssh $foo; done"
|
prop_checkWhileReadPitfalls5 = verifyNot checkWhileReadPitfalls "while read foo; do echo ls | ssh $foo; done"
|
||||||
prop_checkWhileReadPitfalls6 = verifyNot checkWhileReadPitfalls "while read foo <&3; do ssh $foo; done 3< foo"
|
prop_checkWhileReadPitfalls6 = verifyNot checkWhileReadPitfalls "while read foo <&3; do ssh $foo; done 3< foo"
|
||||||
|
prop_checkWhileReadPitfalls7 = verify checkWhileReadPitfalls "while read foo; do if true; then ssh $foo uptime; fi; done < file"
|
||||||
|
|
||||||
checkWhileReadPitfalls _ (T_WhileExpression id [command] contents)
|
checkWhileReadPitfalls _ (T_WhileExpression id [command] contents)
|
||||||
| isStdinReadCommand command = do
|
| isStdinReadCommand command = do
|
||||||
|
@ -2291,13 +2292,19 @@ checkWhileReadPitfalls _ (T_WhileExpression id [command] contents)
|
||||||
&& all (not . stdinRedirect) redirs
|
&& all (not . stdinRedirect) redirs
|
||||||
isStdinReadCommand _ = False
|
isStdinReadCommand _ = False
|
||||||
|
|
||||||
checkMuncher (T_Pipeline _ _ ((T_Redirecting _ redirs cmd):_)) = do
|
checkMuncher (T_Pipeline _ _ ((T_Redirecting _ redirs cmd):_)) | not $ any stdinRedirect redirs = do
|
||||||
let name = fromMaybe "" $ getCommandBasename cmd
|
case cmd of
|
||||||
when ((not . any stdinRedirect $ redirs) && (name `elem` munchers)) $ do
|
(T_IfExpression _ thens elses) ->
|
||||||
info id 2095 $
|
mapM_ checkMuncher . concat $ (map fst thens) ++ (map snd thens) ++ [elses]
|
||||||
name ++ " may swallow stdin, preventing this loop from working properly."
|
|
||||||
warn (getId cmd) 2095 $
|
_ -> potentially $ do
|
||||||
"Add < /dev/null to prevent " ++ name ++ " from swallowing stdin."
|
name <- getCommandBasename cmd
|
||||||
|
guard $ name `elem` munchers
|
||||||
|
return $ do
|
||||||
|
info id 2095 $
|
||||||
|
name ++ " may swallow stdin, preventing this loop from working properly."
|
||||||
|
warn (getId cmd) 2095 $
|
||||||
|
"Add < /dev/null to prevent " ++ name ++ " from swallowing stdin."
|
||||||
checkMuncher _ = return ()
|
checkMuncher _ = return ()
|
||||||
|
|
||||||
stdinRedirect (T_FdRedirect _ fd _)
|
stdinRedirect (T_FdRedirect _ fd _)
|
||||||
|
@ -2694,7 +2701,7 @@ getCommandSequences t =
|
||||||
f (T_UntilExpression _ _ cmds) = [cmds]
|
f (T_UntilExpression _ _ cmds) = [cmds]
|
||||||
f (T_ForIn _ _ _ _ cmds) = [cmds]
|
f (T_ForIn _ _ _ _ cmds) = [cmds]
|
||||||
f (T_ForArithmetic _ _ _ _ cmds) = [cmds]
|
f (T_ForArithmetic _ _ _ _ cmds) = [cmds]
|
||||||
f (T_IfExpression _ thens elses) = elses:(map snd thens)
|
f (T_IfExpression _ thens elses) = (map snd thens) ++ [elses]
|
||||||
f _ = []
|
f _ = []
|
||||||
|
|
||||||
groupWith f l = groupBy (\x y -> f x == f y) l
|
groupWith f l = groupBy (\x y -> f x == f y) l
|
||||||
|
|
Loading…
Reference in New Issue