Skip to content

Fix __unix_fcntl#137

Open
jserv wants to merge 1 commit intotaviso:mainfrom
jserv:fix-fd
Open

Fix __unix_fcntl#137
jserv wants to merge 1 commit intotaviso:mainfrom
jserv:fix-fd

Conversation

@jserv
Copy link
Contributor

@jserv jserv commented Feb 20, 2026

F_SETFL was broken: used the translated command constant instead of the caller's flags from arg, and passed &linuxflags (a pointer) where fcntl expects an int.

This also fixes several related issues in the same function:

  • F_GETFL: errno set unconditionally, leaking stale values on success
  • F_GETLK: input lock region not populated before kernel query
  • F_DUPFD: returned 0 instead of the new file descriptor
  • cmd table indexed without bounds check (OOB on bad input)
  • unmapped table entries silently mapped to F_DUPFD (index 0)
  • F_SETLKW mapped in table but missing from switch (process abort)
  • F_GETFD/F_SETFD mapped in table but missing from switch
  • default case called err() killing the process instead of EINVAL

F_SETFL was broken: used the translated command constant instead of the
caller's flags from arg, and passed &linuxflags (a pointer) where fcntl
expects an int.

This also fixes several related issues in the same function:
- F_GETFL: errno set unconditionally, leaking stale values on success
- F_GETLK: input lock region not populated before kernel query
- F_DUPFD: returned 0 instead of the new file descriptor
- cmd table indexed without bounds check (OOB on bad input)
- unmapped table entries silently mapped to F_DUPFD (index 0)
- F_SETLKW mapped in table but missing from switch (process abort)
- F_GETFD/F_SETFD mapped in table but missing from switch
- default case called err() killing the process instead of EINVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant