Skip to content

Commit b3dbcc8

Browse files
committed
etherscan: make sure the file path is relative
If the file path is absolute, crytic-compile may end up trying to write outside of the expected directory due to the behavior or pathlib.Path Fixes: crytic/slither#1154
1 parent 6bb6e72 commit b3dbcc8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

crytic_compile/platform/etherscan.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ def _handle_multiple_files(
151151
if "contracts" in path_filename.parts and not filename.startswith("@"):
152152
path_filename = Path(*path_filename.parts[path_filename.parts.index("contracts") :])
153153

154+
# Convert "absolute" paths such as "/interfaces/IFoo.sol" into relative ones.
155+
# This is needed due to the following behavior from pathlib.Path:
156+
# > When several absolute paths are given, the last is taken as an anchor
157+
# We need to make sure this is relative, so that Path(directory, ...) remains anchored to directory
158+
if path_filename.is_absolute():
159+
path_filename = Path(*path_filename.parts[1:])
160+
154161
filtered_paths.append(str(path_filename))
155162
path_filename = Path(directory, path_filename)
156163

0 commit comments

Comments
 (0)