From c3873346c6fa1021a1d63bddd9b898a77c618432 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Wed, 21 Sep 2016 17:31:27 +0100 Subject: fetch2: handle absolute paths in subdir Currently if you use the subdir parameter in a SRC_URI and pass an absolute path then it gets appended to the unpack directory instead of being used directly. This is inconvenient as it may be useful to use ${S} when you want to unpack a file into the source tree. Change this behaviour so that absolute paths are used directly instead of being appended to the root directory. To ensure that recipes cannot write files to an arbitrary location enforce that the subdir starts with the unpack root. Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- lib/bb/tests/fetch.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/bb/tests') diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py index d7c73dda0..0fd2c0216 100644 --- a/lib/bb/tests/fetch.py +++ b/lib/bb/tests/fetch.py @@ -508,6 +508,15 @@ class FetcherLocalTest(FetcherTest): tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar']) self.assertEqual(tree, ['bar/dir/subdir/e']) + def test_local_absolutedir(self): + # Unpacking to an absolute path that is a subdirectory of the root + # should work + tree = self.fetchUnpack(['file://a;subdir=%s' % os.path.join(self.unpackdir, 'bar')]) + + # Unpacking to an absolute path outside of the root should fail + with self.assertRaises(bb.fetch2.UnpackError): + self.fetchUnpack(['file://a;subdir=/bin/sh']) + class FetcherNetworkTest(FetcherTest): if os.environ.get("BB_SKIP_NETTESTS") == "yes": -- cgit 1.2.3-korg