20
20
from .. import mesonlib
21
21
from ..mesonlib import (EnvironmentVariables , ExecutableSerialisation , MesonBugException , MesonException , HoldableObject ,
22
22
FileMode , MachineChoice , listify ,
23
- extract_as_list , has_path_sep , path_is_in_root , PerMachine )
23
+ path_starts_with , extract_as_list , has_path_sep , path_is_in_root , PerMachine )
24
24
from ..options import OptionKey
25
25
from ..programs import ExternalProgram , NonExistingExternalProgram
26
26
from ..dependencies import Dependency
@@ -3108,8 +3108,8 @@ def check_clang_asan_lundef(self) -> None:
3108
3108
# subproject than it is defined in (due to e.g. a
3109
3109
# declare_dependency).
3110
3110
def validate_within_subproject (self , subdir , fname ):
3111
- srcdir = Path ( self .environment .source_dir )
3112
- builddir = Path ( self .environment .build_dir )
3111
+ srcdir = self .environment .source_dir
3112
+ builddir = self .environment .build_dir
3113
3113
if isinstance (fname , P_OBJ .DependencyVariableString ):
3114
3114
def validate_installable_file (fpath : Path ) -> bool :
3115
3115
installablefiles : T .Set [Path ] = set ()
@@ -3135,29 +3135,31 @@ def do_validate_within_subproject(norm):
3135
3135
inputtype = 'directory'
3136
3136
else :
3137
3137
inputtype = 'file'
3138
- if InterpreterRuleRelaxation .ALLOW_BUILD_DIR_FILE_REFERENCES in self .relaxations and builddir in norm . parents :
3138
+ if InterpreterRuleRelaxation .ALLOW_BUILD_DIR_FILE_REFERENCES in self .relaxations and path_starts_with ( norm , self . environment . build_dir ) :
3139
3139
return
3140
- if srcdir not in norm .parents :
3140
+
3141
+ if not path_starts_with (norm , self .environment .source_dir ):
3141
3142
# Grabbing files outside the source tree is ok.
3142
3143
# This is for vendor stuff like:
3143
3144
#
3144
3145
# /opt/vendorsdk/src/file_with_license_restrictions.c
3145
3146
return
3146
- project_root = Path (srcdir , self .root_subdir )
3147
- subproject_dir = project_root / self .subproject_dir
3148
- if norm == project_root :
3149
- return
3150
- if project_root not in norm .parents :
3151
- raise InterpreterException (f'Sandbox violation: Tried to grab { inputtype } { norm .name } outside current (sub)project.' )
3152
- if subproject_dir == norm or subproject_dir in norm .parents :
3153
- raise InterpreterException (f'Sandbox violation: Tried to grab { inputtype } { norm .name } from a nested subproject.' )
3147
+
3148
+ project_root = os .path .join (self .environment .source_dir , self .root_subdir , '' )
3149
+ if not path_starts_with (norm , project_root ):
3150
+ name = os .path .basename (norm )
3151
+ raise InterpreterException (f'Sandbox violation: Tried to grab { inputtype } { name } outside current (sub)project.' )
3152
+
3153
+ subproject_dir = os .path .join (project_root , self .subproject_dir )
3154
+ if path_starts_with (norm , subproject_dir ):
3155
+ name = os .path .basename (norm )
3156
+ raise InterpreterException (f'Sandbox violation: Tried to grab { inputtype } { name } from a nested subproject.' )
3154
3157
3155
3158
fname = os .path .join (subdir , fname )
3156
3159
if fname in self .validated_cache :
3157
3160
return
3158
3161
3159
- # Use os.path.abspath() to eliminate .. segments, but do not resolve symlinks
3160
- norm = Path (os .path .abspath (Path (srcdir , fname )))
3162
+ norm = os .path .abspath (os .path .join (srcdir , fname ))
3161
3163
do_validate_within_subproject (norm )
3162
3164
self .validated_cache .add (fname )
3163
3165
0 commit comments