Add extra checks for masked return codes

This commit is contained in:
Christian Nassif-Haynes 2021-09-06 05:52:34 +10:00
parent 3a296cd788
commit 093df8cb24
4 changed files with 129 additions and 2 deletions

View file

@ -83,6 +83,8 @@ data Parameters = Parameters {
hasInheritErrexit :: Bool,
-- Whether this script has 'set -e' anywhere.
hasSetE :: Bool,
-- Whether this script has 'set -o pipefail' anywhere.
hasPipefail :: Bool,
-- A linear (bad) analysis of data flow
variableFlow :: [StackData],
-- A map from Id to parent Token
@ -204,6 +206,12 @@ makeParameters spec =
Dash -> True
Sh -> True
Ksh -> False,
hasPipefail =
case shellType params of
Bash -> containsPipefail root
Dash -> True
Sh -> True
Ksh -> containsPipefail root,
shellTypeSpecified = isJust (asShellType spec) || isJust (asFallbackShell spec),
parentMap = getParentTree root,
variableFlow = getVariableFlow params root,
@ -226,6 +234,16 @@ containsSetE root = isNothing $ doAnalysis (guard . not . isSetE) root
_ -> False
re = mkRegex "[[:space:]]-[^-]*e"
containsPipefail root = isNothing $ doAnalysis (guard . not . isPipefail) root
where
isPipefail t =
case t of
T_SimpleCommand {} ->
t `isUnqualifiedCommand` "set" &&
("pipefail" `elem` oversimplify t ||
"o" `elem` map snd (getAllFlags t))
_ -> False
containsShopt shopt root =
isNothing $ doAnalysis (guard . not . isShoptLastPipe) root
where