`os.chmod` is missing validation for `dir_fd` and `follow_symlinks` when `path` is a file descriptor
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
The documentation for os.chmod says it is not correct to use dir_fd or follow_symlinks when path is an open file descriptor...
... but os_chmod_impl never checks it.
When path->is_fd is true it takes the fchmod path and returns success, so both keywords are ignored altogether:
Other os utils (I checked os.stat, os.chown, and os.utime) reject this combination with dir_fd_and_fd_invalid / fd_and_follow_symlinks_invalid before the syscall. os.chown for example:
(The Windows path also has the same problem with: path->is_fd going directly to win32_fchmod.)
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-156265
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Modules/posixmodule.c at os_chmod_impl and inspect the path->is_fd branches for POSIX and Windows. Compare their handling with the validation used by os.chown, os.stat, and os.utime. Done means invalid dir_fd and follow_symlinks combinations are rejected when path is a file descriptor, with behavior covered by the relevant os tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100