python / python/cpython

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

Offen
#156,264 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

extension-modules type-feature
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in Modules/posixmodule.c bei os_chmod_impl und untersuche die path->is_fd-Zweige für POSIX und Windows. Vergleiche deren Verarbeitung mit der von os.chown, os.stat und os.utime verwendeten Validierung. Erledigt ist die Aufgabe, wenn ungültige Kombinationen aus dir_fd und follow_symlinks abgewiesen werden, sobald path ein Dateideskriptor ist, und das Verhalten durch die relevanten os-Tests abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
operating-systems
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.