From 647d19c436c4cc9a767d96db90059750986cc1f1 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 3 Apr 2024 09:21:27 +0200 Subject: AtLocation.readlink: require AT_SYMLINK_NOFOLLOW It does not make sense to read a link after having followed it. --- linuxnamespaces/atlocation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'linuxnamespaces') diff --git a/linuxnamespaces/atlocation.py b/linuxnamespaces/atlocation.py index 79f55bb..66b0947 100644 --- a/linuxnamespaces/atlocation.py +++ b/linuxnamespaces/atlocation.py @@ -413,7 +413,9 @@ class AtLocation: def readlink(self) -> str: """Wrapper for os.readlink supplying path and dir_fd.""" - if self.flags & ~AtFlags.AT_EMPTY_PATH != AtFlags.NONE: + if self.flags & AtFlags.AT_SYMLINK_NOFOLLOW == AtFlags.NONE: + raise NotImplementedError("cannot read a link after following it") + if self.flags & ~AtFlags.AT_EMPTY_PATH != AtFlags.AT_SYMLINK_NOFOLLOW: raise NotImplementedError( "readlink on AtLocation only support flag AT_EMPTY_PATH" ) -- cgit v1.2.3