fix associatedfile sanity check
It seems best to require that the file just be relative, and not some ../ trick. git-annex-shell sendkey and recvkey both update transfer information now
This commit is contained in:
parent
8f6c2e6081
commit
bdcabb3cfa
2 changed files with 8 additions and 8 deletions
10
Fields.hs
10
Fields.hs
|
@ -15,18 +15,18 @@ import Data.Char
|
||||||
{- A field, stored in Annex state, with a value sanity checker. -}
|
{- A field, stored in Annex state, with a value sanity checker. -}
|
||||||
data Field = Field
|
data Field = Field
|
||||||
{ fieldName :: String
|
{ fieldName :: String
|
||||||
, fieldCheck :: String -> IO Bool
|
, fieldCheck :: String -> Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteUUID :: Field
|
remoteUUID :: Field
|
||||||
remoteUUID = Field "remoteuuid" $
|
remoteUUID = Field "remoteuuid" $
|
||||||
-- does it look like a UUID?
|
-- does it look like a UUID?
|
||||||
return . all (\c -> isAlphaNum c || c == '-')
|
all (\c -> isAlphaNum c || c == '-')
|
||||||
|
|
||||||
associatedFile :: Field
|
associatedFile :: Field
|
||||||
associatedFile = Field "associatedfile" $ \value ->
|
associatedFile = Field "associatedfile" $ \f ->
|
||||||
-- is the file located within the current directory?
|
-- is the file a safe relative filename?
|
||||||
dirContains <$> getCurrentDirectory <*> pure value
|
not (isAbsolute f) && not ("../" `isPrefixOf` f)
|
||||||
|
|
||||||
getField :: Field -> Annex (Maybe String)
|
getField :: Field -> Annex (Maybe String)
|
||||||
getField = Annex.getField . fieldName
|
getField = Annex.getField . fieldName
|
||||||
|
|
|
@ -85,7 +85,7 @@ builtin :: String -> String -> [String] -> IO ()
|
||||||
builtin cmd dir params = do
|
builtin cmd dir params = do
|
||||||
checkNotReadOnly cmd
|
checkNotReadOnly cmd
|
||||||
let (params', fieldparams) = partitionParams params
|
let (params', fieldparams) = partitionParams params
|
||||||
fields <- filterM checkField $ parseFields fieldparams
|
let fields = filter checkField $ parseFields fieldparams
|
||||||
dispatch False (cmd : params') cmds options fields header $
|
dispatch False (cmd : params') cmds options fields header $
|
||||||
Git.Construct.repoAbsPath dir >>= Git.Construct.fromAbsPath
|
Git.Construct.repoAbsPath dir >>= Git.Construct.fromAbsPath
|
||||||
|
|
||||||
|
@ -113,11 +113,11 @@ parseFields = map (separate (== '='))
|
||||||
|
|
||||||
{- Only allow known fields to be set, ignore others.
|
{- Only allow known fields to be set, ignore others.
|
||||||
- Make sure that field values make sense. -}
|
- Make sure that field values make sense. -}
|
||||||
checkField :: (String, String) -> IO Bool
|
checkField :: (String, String) -> Bool
|
||||||
checkField (field, value)
|
checkField (field, value)
|
||||||
| field == fieldName remoteUUID = fieldCheck remoteUUID value
|
| field == fieldName remoteUUID = fieldCheck remoteUUID value
|
||||||
| field == fieldName associatedFile = fieldCheck associatedFile value
|
| field == fieldName associatedFile = fieldCheck associatedFile value
|
||||||
| otherwise = return False
|
| otherwise = False
|
||||||
|
|
||||||
failure :: IO ()
|
failure :: IO ()
|
||||||
failure = error $ "bad parameters\n\n" ++ usage header cmds options
|
failure = error $ "bad parameters\n\n" ++ usage header cmds options
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue