[commit: ghc] ghc-7.8: Don't perform permission checks for scripts named with -ghci-script (#6017) (22402de)
git at git.haskell.org
git at git.haskell.org
Mon Apr 14 13:53:18 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-7.8
Link : http://ghc.haskell.org/trac/ghc/changeset/22402debae0109988eb9484edbd83e29b10b27d2/ghc
>---------------------------------------------------------------
commit 22402debae0109988eb9484edbd83e29b10b27d2
Author: Simon Marlow <marlowsd at gmail.com>
Date: Thu Mar 20 21:47:22 2014 +0000
Don't perform permission checks for scripts named with -ghci-script (#6017)
The user explicitly requested this script on the command-line, so it's
unnecessary to require that the script is also owned by the user.
Also, it is currently impossible to make a GHCi wrapper that invokes a
custom script without first making a copy of the script to circumvent
the permissions check, which seems wrong.
(cherry picked from commit a6f2c852d49313fa8acea2deb3741ab86c6ef995)
>---------------------------------------------------------------
22402debae0109988eb9484edbd83e29b10b27d2
ghc/InteractiveUI.hs | 26 ++++++++++++++++++--------
ghc/ghc-bin.cabal.in | 1 +
2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs
index 1476f95..b41c2db 100644
--- a/ghc/InteractiveUI.hs
+++ b/ghc/InteractiveUI.hs
@@ -455,13 +455,18 @@ runGHCi paths maybe_exprs = do
canonicalizePath' fp = liftM Just (canonicalizePath fp)
`catchIO` \_ -> return Nothing
- sourceConfigFile :: FilePath -> GHCi ()
- sourceConfigFile file = do
+ sourceConfigFile :: (FilePath, Bool) -> GHCi ()
+ sourceConfigFile (file, check_perms) = do
exists <- liftIO $ doesFileExist file
when exists $ do
- dir_ok <- liftIO $ checkPerms (getDirectory file)
- file_ok <- liftIO $ checkPerms file
- when (dir_ok && file_ok) $ do
+ perms_ok <-
+ if not check_perms
+ then return True
+ else do
+ dir_ok <- liftIO $ checkPerms (getDirectory file)
+ file_ok <- liftIO $ checkPerms file
+ return (dir_ok && file_ok)
+ when perms_ok $ do
either_hdl <- liftIO $ tryIO (openFile file ReadMode)
case either_hdl of
Left _e -> return ()
@@ -479,9 +484,14 @@ runGHCi paths maybe_exprs = do
setGHCContextFromGHCiState
when (read_dot_files) $ do
- mcfgs0 <- sequence $ [ current_dir, app_user_dir, home_dir ] ++ map (return . Just ) (ghciScripts dflags)
- mcfgs <- liftIO $ mapM canonicalizePath' (catMaybes mcfgs0)
- mapM_ sourceConfigFile $ nub $ catMaybes mcfgs
+ mcfgs0 <- catMaybes <$> sequence [ current_dir, app_user_dir, home_dir ]
+ let mcfgs1 = zip mcfgs0 (repeat True)
+ ++ zip (ghciScripts dflags) (repeat False)
+ -- False says "don't check permissions". We don't
+ -- require that a script explicitly added by
+ -- -ghci-script is owned by the current user. (#6017)
+ mcfgs <- liftIO $ mapM (\(f, b) -> (,b) <$> canonicalizePath' f) mcfgs1
+ mapM_ sourceConfigFile $ nub $ [ (f,b) | (Just f, b) <- mcfgs ]
-- nub, because we don't want to read .ghci twice if the
-- CWD is $HOME.
diff --git a/ghc/ghc-bin.cabal.in b/ghc/ghc-bin.cabal.in
index 561c55c..68338f3 100644
--- a/ghc/ghc-bin.cabal.in
+++ b/ghc/ghc-bin.cabal.in
@@ -48,6 +48,7 @@ Executable ghc
Extensions: ForeignFunctionInterface,
UnboxedTuples,
FlexibleInstances,
+ TupleSections,
MagicHash
Extensions: CPP, PatternGuards, NondecreasingIndentation
More information about the ghc-commits
mailing list