python / python/cpython

`os.chmod` is missing validation for `dir_fd` and `follow_symlinks` when `path` is a file descriptor

オープン
#156,264 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

extension-modules type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

https://github.com/python/cpython/blob/f74cdf80a120649e4c353430da8cbd1305c00993/Modules/posixmodule.c#L4092-L4095

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

https://github.com/python/cpython/blob/f74cdf80a120649e4c353430da8cbd1305c00993/Modules/posixmodule.c#L4146-L4149

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:

https://github.com/python/cpython/blob/f74cdf80a120649e4c353430da8cbd1305c00993/Modules/posixmodule.c#L4548-L4550

(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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Modules/posixmodule.c の os_chmod_impl から始め、POSIX と Windows の path->is_fd 分岐を調べてください。os.chown、os.stat、os.utime で使用されている検証と、それらの処理を比較してください。path がファイルディスクリプタの場合に、無効な dir_fd と follow_symlinks の組み合わせが拒否され、関連する os テストでその動作がカバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
operating-systems
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。