Skip to content
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

"exclusive = True" may lead to undefined behavior #58

Closed
hasufell opened this issue May 1, 2016 · 0 comments · Fixed by #224
Closed

"exclusive = True" may lead to undefined behavior #58

hasufell opened this issue May 1, 2016 · 0 comments · Fixed by #224
Milestone

Comments

@hasufell
Copy link
Member

hasufell commented May 1, 2016

It's not very well documented, because O_CREAT is not passed like the other flags via OpenFileFlags, but implicitly via Maybe FileMode.

The manpage says that

If O_EXCL is set and O_CREAT is not set, the result is undefined.

This library should either make the correspondence of those input arguments clear or make it impossible to use the combination. The following would already be quite an improvement:

-- |Correspond to some of the int flags from C's fcntl.h.
data OpenFileFlags =
 OpenFileFlags {
    append    :: Bool,           -- ^ O_APPEND
    exclusive :: Bool,           -- ^ O_EXCL, result is undefined if O_CREAT is False
    noctty    :: Bool,           -- ^ O_NOCTTY
    nonBlock  :: Bool,           -- ^ O_NONBLOCK
    trunc     :: Bool,           -- ^ O_TRUNC
    creat     :: Maybe FileMode  -- ^ O_CREAT 
 }

And then remove the extraneous Maybe FileMode arguments from open_.

hasufell added a commit to hasufell/unix that referenced this issue May 1, 2016
hasufell added a commit to hasufell/unix that referenced this issue May 1, 2016
hvr pushed a commit that referenced this issue Feb 23, 2018
* Add support for `O_NOFOLLOW`, `O_CLOEXEC`, `O_DIRECTORY` and `O_SYNC`
   (#6, #57)

* Refactor API of `openFd` removing `Maybe FileMode` argument,
   which now must be passed as part of `OpenFileFlags`
   (e.g. `defaultFileFlags { creat = Just mode }`)  (#58)

Closes #59
@hasufell hasufell added this to the 2.8.0.0 milestone Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant