Warn when using read without -r

This commit is contained in:
Vidar Holen 2015-07-18 12:30:08 -07:00
parent d406ba9950
commit b1843c520f
1 changed files with 8 additions and 0 deletions

View File

@ -206,6 +206,7 @@ nodeChecks = [
,checkReturn
,checkMaskedReturns
,checkInjectableFindSh
,checkReadWithoutR
]
@ -3453,6 +3454,13 @@ checkInjectableFindSh _ = checkCommand "find" (const check)
when ("{}" `isInfixOf` arg) $
warn id 2156 "Injecting filenames is fragile and insecure. Use parameters."
prop_checkReadWithoutR1 = verify checkReadWithoutR "read -a foo"
prop_checkReadWithoutR2 = verifyNot checkReadWithoutR "read -ar foo"
checkReadWithoutR _ t@(T_SimpleCommand {}) | t `isUnqualifiedCommand` "read" =
unless ("r" `elem` map snd (getAllFlags t)) $
info (getId t) 2162 "read without -r will mangle backslashes."
checkReadWithoutR _ _ = return ()
return []
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])