Skip to content

Commit b896a3c

Browse files
committed
custom target: Allow fetching outputs from built subdirs
Change the check for `/` to checking for `..` to prevent custom targets from fetching outputs from outside the target directory, but allow fetching outputs from arbitrarily-nested subdirs. Also disallow absolute paths for outputs for similar reasons.
1 parent 054910a commit b896a3c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

mesonbuild/build.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import copy, os, re
16+
from pathlib import PurePath
1617
from collections import OrderedDict
1718
import itertools
1819

@@ -1584,10 +1585,13 @@ def process_kwargs(self, kwargs):
15841585
inputs = get_sources_string_names(self.sources)
15851586
values = get_filenames_templates_dict(inputs, [])
15861587
for i in self.outputs:
1587-
if not(isinstance(i, str)):
1588+
if not isinstance(i, str):
15881589
raise InvalidArguments('Output argument not a string.')
1589-
if '/' in i:
1590-
raise InvalidArguments('Output must not contain a path segment.')
1590+
ipath = PurePath(i)
1591+
if ipath.is_absolute():
1592+
raise InvalidArguments('Output must not be an absolute path')
1593+
if '..' in ipath.parts:
1594+
raise InvalidArguments('Output path must not contain ".."')
15911595
if '@INPUT@' in i or '@INPUT0@' in i:
15921596
m = 'Output cannot contain @INPUT@ or @INPUT0@, did you ' \
15931597
'mean @PLAINNAME@ or @BASENAME@?'
@@ -1608,8 +1612,11 @@ def process_kwargs(self, kwargs):
16081612
depfile = kwargs['depfile']
16091613
if not isinstance(depfile, str):
16101614
raise InvalidArguments('Depfile must be a string.')
1611-
if os.path.split(depfile)[1] != depfile:
1612-
raise InvalidArguments('Depfile must be a plain filename without a subdirectory.')
1615+
deppath = PurePath(depfile)
1616+
if deppath.is_absolute():
1617+
raise InvalidArguments('Depfile must not be an absolute path')
1618+
if '..' in deppath.parts:
1619+
raise InvalidArguments('Depfile must not contain ".."')
16131620
self.depfile = depfile
16141621
self.command = self.flatten_command(kwargs['command'])
16151622
if self.capture:

0 commit comments

Comments
 (0)