@@ -49,29 +49,39 @@ def init(config, benchmark):
4949 executable_for_version = benchmark .tool .executable (tool_locator )
5050 benchmark .tool_version = benchmark .tool .version (executable_for_version )
5151
52- # If the tool info does not call find_executable, we don't know if the
53- # executable path is containing the mount point.
54- # In this case we can check whether the path is relative
55- # and continue with the assumption that it is relative to the provided
56- # tool directory.
57- try :
58- executable_relative_to_mount_point = Path (
59- executable_for_version
60- ).relative_to (TOOL_DIRECTORY_MOUNT_POINT )
61- except ValueError :
62- if Path (executable_for_version ).is_absolute ():
63- raise ValueError (
52+ executable_for_version = Path (executable_for_version )
53+
54+ # ensure executable_for_version is relative
55+ if executable_for_version .is_absolute ():
56+ try :
57+ executable_for_version = executable_for_version .relative_to (
58+ TOOL_DIRECTORY_MOUNT_POINT
59+ )
60+ except ValueError as e :
61+ raise BenchExecException (
6462 f"Executable path { executable_for_version } is not relative"
65- " and is not containing the expected container to the mount point"
66- " {TOOL_DIRECTORY_MOUNT_POINT}"
67- ) from None
68- executable_relative_to_mount_point = executable_for_version
63+ " and is not containing the expected mount point in the container"
64+ " {TOOL_DIRECTORY_MOUNT_POINT}."
65+ ) from e
66+
67+ # ensure that executable_for_version is not pointing to a directory
68+ # outside of the tool directory
69+
70+ executable_for_cloud = Path (config .tool_directory ) / executable_for_version
71+
72+ # Paths must be resolved to properly detect when the executable would
73+ # escape the tool dir with '..'
74+ if not executable_for_cloud .resolve ().is_relative_to (
75+ Path (config .tool_directory ).resolve ()
76+ ):
77+ raise BenchExecException (
78+ f"Executable path { executable_for_cloud } is not within the tool directory"
79+ f" { config .tool_directory } ."
80+ )
6981
7082 # The vcloud uses the tool location later to determine which files need to be uploaded
7183 # So this needs to point to the actual path where the executable is on the host
72- benchmark .executable = str (
73- Path (config .tool_directory ) / executable_relative_to_mount_point
74- )
84+ benchmark .executable = str (executable_for_cloud )
7585
7686 else :
7787 tool_locator = create_tool_locator (config )
0 commit comments