python / python/cpython

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

Đang mở
#156,264 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

extension-modules type-feature
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong Modules/posixmodule.c tại os_chmod_impl và kiểm tra các nhánh path->is_fd cho POSIX và Windows. So sánh cách xử lý của chúng với việc xác thực được os.chown, os.stat và os.utime sử dụng. Hoàn tất khi các tổ hợp dir_fd và follow_symlinks không hợp lệ bị từ chối khi path là một bộ mô tả tệp, đồng thời hành vi này được bao phủ bởi các kiểm thử os liên quan.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
operating-systems
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.