-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
posixpath.realpath('secretlink')
raises
#118447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Setting permissions on a symlink is a BSD (including macOS) feature. Linux doesn't allow it. Testing this should be limited to platforms with |
Upon closer inspection, this is a bug in coreutils: wannes@Stefans-iMac dirs % sudo ls -l secret-recursive-symlink
l--------- 1 wannes staff 40 Jun 30 2023 secret-recursive-symlink -> /Users/wannes/path-picker/link-test/dirs
wannes@Stefans-iMac dirs % sudo realpath secret-recursive-symlink/..
/Users/wannes/path-picker/link-test
wannes@Stefans-iMac dirs % grealpath -m secret-recursive-symlink/..
/Users/wannes/path-picker/link-test/dirs |
I wouldn't expect |
That's probably a reason which this is not part of POSIX... I expected you needed permission to follow it, not to determine the real location.
We can't eliminate this symlink, because we don't know where it points to, wannes@Stefans-iMac ~ % ln -s . src
wannes@Stefans-iMac ~ % grealpath -e src/..
/Users
wannes@Stefans-iMac ~ % chmod -h 000 src
wannes@Stefans-iMac ~ % grealpath -e src/..
/Users/wannes
|
On macOS and NetBSD, |
That works: >>> import fcntl
>>> import os
>>> os.symlink('.', 'src')
>>> os.chmod('src', 0o000, follow_symlinks=False)
>>> os.readlink('src')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: 'src'
>>> fd = os.open('src', os.O_RDONLY)
>>> os.fsdecode(fcntl.fcntl(fd, fcntl.F_GETPATH, bytes(1024))).rstrip('\x00')
'/Users/wannes' But I think it might be cleaner to fix this in readlink... |
But it doesn't work for broken symlinks: >>> import fcntl
>>> import os
>>> open('tmp', 'w', encoding='utf-8')
<_io.TextIOWrapper name='tmp' mode='w' encoding='utf-8'>
>>> os.symlink('tmp', 'dst')
>>> os.unlink('tmp')
>>> os.chmod('dst', 0o000, follow_symlinks=False)
>>> os.readlink('dst')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
PermissionError: [Errno 13] Permission denied: 'dst'
>>> fd = os.open('dst', os.O_RDONLY)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'dst' |
#118489) Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
…path()` (pythonGH-118489) (cherry picked from commit caf6064) Co-authored-by: Barney Gale <barney.gale@gmail.com> Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
…path()` (python#118489) Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com> (cherry picked from commit caf6064)
…th.realpath()` (pythonGH-118489) Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>. (cherry picked from commit caf6064) Co-authored-by: Barney Gale <barney.gale@gmail.com>
Apparently only macOS requires read permission to call `readlink()` on a symlink.
Apparently only macOS requires read permission to call `readlink()` on a symlink.
Apparently only macOS requires read permission to call `readlink()` on a symlink. (cherry picked from commit 4b76671) Co-authored-by: Barney Gale <barney.gale@gmail.com>
With the FreeBSD test failures fixed, we can close this. |
…path()` (python#118489) Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
Apparently only macOS requires read permission to call `readlink()` on a symlink.
Bug report
Bug description:
GNU coreutils
realpath -m
doesn't raise an error for secret symlinks (no read permission):But
posixpath.realpath()
does:CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
os.path.realpath()
#118489os.path.realpath()
(GH-118489) #119163The text was updated successfully, but these errors were encountered: