[commit: ghc] ghc-8.2: base: Check for path separators chars in openTempFile' template string (02a9c6a)

git at git.haskell.org git at git.haskell.org
Wed Mar 29 23:41:31 UTC 2017


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

On branch  : ghc-8.2
Link       : http://ghc.haskell.org/trac/ghc/changeset/02a9c6a3442c1b560176ec01789c0042c655c0eb/ghc

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

commit 02a9c6a3442c1b560176ec01789c0042c655c0eb
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.
    
    (cherry picked from commit b04ded8fca8ee8b0cd9c7c055bc5dc61ef2be1fe)


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

02a9c6a3442c1b560176ec01789c0042c655c0eb
 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