diff --git a/System/Posix/ByteString/FilePath.hsc b/System/Posix/ByteString/FilePath.hsc index 6b0ac4c..742c85b 100644 --- a/System/Posix/ByteString/FilePath.hsc +++ b/System/Posix/ByteString/FilePath.hsc @@ -153,7 +153,8 @@ decodeWithBasePosix ba = B.useAsCStringLen ba $ \fp -> peekFilePathPosix fp -- | Wrapper around 'useAsCString', checking the encoded 'FilePath' for internal NUL octets as these are -- disallowed in POSIX filepaths. See https://gitlab.haskell.org/ghc/ghc/-/issues/13660 useAsCStringSafe :: RawFilePath -> (CString -> IO a) -> IO a -useAsCStringSafe path f = useAsCStringLen path $ \(ptr, len) -> do +useAsCStringSafe path f = useAsCString path $ \ptr -> do + let len = B.length path clen <- c_strlen ptr if clen == fromIntegral len then f ptr diff --git a/System/Posix/PosixPath/FilePath.hsc b/System/Posix/PosixPath/FilePath.hsc index 09d73f8..55be067 100644 --- a/System/Posix/PosixPath/FilePath.hsc +++ b/System/Posix/PosixPath/FilePath.hsc @@ -45,7 +45,7 @@ import Data.ByteString.Internal (c_strlen) import Control.Monad import Control.Exception import System.OsPath.Posix as PS -import System.OsPath.Data.ByteString.Short +import System.OsPath.Data.ByteString.Short as BSS import Prelude hiding (FilePath) import System.OsString.Internal.Types (PosixString(..), pattern PS) import GHC.IO.Exception @@ -147,7 +147,8 @@ _toStr = fmap PS.toChar . PS.unpack -- | Wrapper around 'useAsCString', checking the encoded 'FilePath' for internal NUL octets as these are -- disallowed in POSIX filepaths. See https://gitlab.haskell.org/ghc/ghc/-/issues/13660 useAsCStringSafe :: PosixPath -> (CString -> IO a) -> IO a -useAsCStringSafe pp@(PS path) f = useAsCStringLen path $ \(ptr, len) -> do +useAsCStringSafe pp@(PS path) f = useAsCString path $ \ptr -> do + let len = BSS.length path clen <- c_strlen ptr if clen == fromIntegral len then f ptr