Skip to content

Fix withFilePath #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion System/Posix/ByteString/FilePath.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions System/Posix/PosixPath/FilePath.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for [`unix` package](http://hackage.haskell.org/package/unix)

## 2.8.2.1 *Sep 2023*

* Fix UB bug in `withFilePath` that causes it to error out (introduced in 2.8.2.0) wrt [#295](https://github.com/haskell/unix/issues/295)

## 2.8.2.0 *Sep 2023*

* Bump bounds to accomodate `base-4.19` and `bytestring-0.12`.
Expand Down
2 changes: 1 addition & 1 deletion unix.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 1.12
name: unix
version: 2.8.2.0
version: 2.8.2.1
-- NOTE: Don't forget to update ./changelog.md

license: BSD3
Expand Down