mirror of
https://github.com/python/cpython.git
synced 2025-08-23 02:04:56 +00:00
gh-94692: Only catch OSError in shutil.rmtree() (#112756)
Previously a symlink attack resistant version of shutil.rmtree() could ignore or pass to the error handler arbitrary exception when invalid arguments were provided.
This commit is contained in:
parent
bc68f4a4ab
commit
563ccded6e
3 changed files with 22 additions and 19 deletions
|
@ -768,13 +768,13 @@ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
|
|||
# lstat()/open()/fstat() trick.
|
||||
try:
|
||||
orig_st = os.lstat(path, dir_fd=dir_fd)
|
||||
except Exception as err:
|
||||
except OSError as err:
|
||||
onexc(os.lstat, path, err)
|
||||
return
|
||||
try:
|
||||
fd = os.open(path, os.O_RDONLY, dir_fd=dir_fd)
|
||||
fd_closed = False
|
||||
except Exception as err:
|
||||
except OSError as err:
|
||||
onexc(os.open, path, err)
|
||||
return
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue