[GHC] #7161: hSetNewlineMode and hSetEncoding can be performed on closed and semi-closed handles
GHC
ghc-devs at haskell.org
Sun Dec 13 00:54:33 UTC 2015
#7161: hSetNewlineMode and hSetEncoding can be performed on closed and semi-closed
handles
-------------------------------------+-------------------------------------
Reporter: duncan | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 8.0.1
Component: Core Libraries | Version: 7.6.1-rc1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by thomie):
* status: infoneeded => new
* cc: ekmett (added)
Old description:
> The `hSetNewlineMode` and `hSetEncoding` functions from
> `GHC/IO/Handle.hs` do not check that the Handle is in an open mode. It is
> possible to use them on closed handles. hSetEncoding on a closed Handle
> triggers a segfault. Similarly, the operations are also both possible on
> semi-closed handles, and given the way hGetContents is implemented, this
> will affect the result of hGetContents which is clearly against the
> intention of the hGetContents/semi-closed stuff.
>
> Both functions use the `withAllHandles__` helper. Unlike similar helpers
> like `wantReadableHandle_` this one doesn't do any handle mode checking.
>
> Additionally, `hSetBuffering` and `hSetBinary` mode also use the
> `withAllHandles__` pattern and don't obviously check for an open handle
> but I've not verified this.
New description:
The `hSetNewlineMode` and `hSetEncoding` functions from `GHC/IO/Handle.hs`
do not check that the Handle is in an open mode. It is possible to use
them on closed handles. hSetEncoding on a closed Handle triggers a
segfault. Similarly, the operations are also both possible on semi-closed
handles, and given the way hGetContents is implemented, this will affect
the result of hGetContents which is clearly against the intention of the
hGetContents/semi-closed stuff.
Both functions use the `withAllHandles__` helper. Unlike similar helpers
like `wantReadableHandle_` this one doesn't do any handle mode checking.
Additionally, `hSetBuffering` and `hSetBinaryMode` mode also use the
`withAllHandles__` pattern and don't obviously check for an open handle
but I've not verified this.
--
Comment:
With or without segfaults, this could be fixed.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7161#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list