[commit: ghc] master: base: Check for path separators chars in openTempFile' template string (b04ded8)

git at git.haskell.org git at git.haskell.org
Wed Mar 29 20:53:34 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/b04ded8fca8ee8b0cd9c7c055bc5dc61ef2be1fe/ghc

>---------------------------------------------------------------

commit b04ded8fca8ee8b0cd9c7c055bc5dc61ef2be1fe
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Mon Mar 27 12:40:42 2017 -0400

    base: Check for path separators chars in openTempFile' template string
    
    This fixes #13489.


>---------------------------------------------------------------

b04ded8fca8ee8b0cd9c7c055bc5dc61ef2be1fe
 libraries/base/System/IO.hs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libraries/base/System/IO.hs b/libraries/base/System/IO.hs
index d1ed9e3..1796200 100644
--- a/libraries/base/System/IO.hs
+++ b/libraries/base/System/IO.hs
@@ -441,7 +441,8 @@ fixIO k = do
 openTempFile :: FilePath   -- ^ Directory in which to create the file
              -> String     -- ^ File name template. If the template is \"foo.ext\" then
                            -- the created file will be \"fooXXX.ext\" where XXX is some
-                           -- random number.
+                           -- random number. Note that this should not contain any path
+                           -- separator characters.
              -> IO (FilePath, Handle)
 openTempFile tmp_dir template
     = openTempFile' "openTempFile" tmp_dir template False 0o600
@@ -465,7 +466,10 @@ openBinaryTempFileWithDefaultPermissions tmp_dir template
 
 openTempFile' :: String -> FilePath -> String -> Bool -> CMode
               -> IO (FilePath, Handle)
-openTempFile' loc tmp_dir template binary mode = findTempName
+openTempFile' loc tmp_dir template binary mode
+    | pathSeparator `elem` template
+    = fail $ "openTempFile': Template string must not contain path separator characters: "++template
+    | otherwise = findTempName
   where
     -- We split off the last extension, so we can use .foo.ext files
     -- for temporary files (hidden on Unix OSes). Unfortunately we're



More information about the ghc-commits mailing list