Skip to content

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

Description

@hasufell

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_.

Activity

  1. added 2 commits that reference this issue on May 1, 2016
    6ad9639
    2c812bf
  2. added this to the 2.8.0.0 milestone on Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions