Skip to content

Commit

Permalink
Forbid all absolute symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
gkreitz committed May 25, 2024
1 parent 7f6a73c commit 0ced1ad
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions problemtools/verifyproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1871,8 +1871,7 @@ def _check_symlinks(self):
filename = os.path.join(root, file)
if os.path.islink(filename):
target = os.path.realpath(filename)
# We only use these relative paths to give a nice error message.
# relfile is the filename of the symlink, relative to the problem root
# relfile is the filename of the symlink, relative to the problem root (only used for nicer error messages)
relfile = os.path.relpath(filename, self.probdir)
# reltarget is what the symlink points to (absolute, or relative to where the symlink is)
reltarget = os.readlink(filename)
Expand All @@ -1884,6 +1883,10 @@ def _check_symlinks(self):
self.error(
f"Symlink {relfile} links to {reltarget} which is outside of problem package"
)
if os.path.isabs(reltarget):
self.error(
f"Symlink {relfile} links to {reltarget} which is an absolute path. Symlinks must be relative."
)

def re_argument(s: str) -> Pattern[str]:
try:
Expand Down

0 comments on commit 0ced1ad

Please sign in to comment.