All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fetch2: handle absolute paths in subdir
@ 2016-09-21 16:48 Ross Burton
  2016-09-21 21:09 ` Christopher Larson
  0 siblings, 1 reply; 2+ messages in thread
From: Ross Burton @ 2016-09-21 16:48 UTC (permalink / raw)
  To: bitbake-devel

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 <ross.burton@intel.com>
---
 bitbake/lib/bb/fetch2/__init__.py | 8 +++++++-
 bitbake/lib/bb/tests/fetch.py     | 9 +++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 06f1eb4..cd7362c 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -1420,7 +1420,13 @@ class FetchMethod(object):
 
         # If 'subdir' param exists, create a dir and use it as destination for unpack cmd
         if 'subdir' in urldata.parm:
-            unpackdir = '%s/%s' % (rootdir, urldata.parm.get('subdir'))
+            subdir = urldata.parm.get('subdir')
+            if os.path.isabs(subdir):
+                if not os.path.realpath(subdir).startswith(os.path.realpath(rootdir)):
+                    raise UnpackError("subdir argument isn't a subdirectory of unpack root %s" % rootdir, urldata.url)
+                unpackdir = subdir
+            else:
+                unpackdir = os.path.join(rootdir, subdir)
             bb.utils.mkdirhier(unpackdir)
         else:
             unpackdir = rootdir
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index d7c73dd..0fd2c02 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/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":
-- 
2.8.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] fetch2: handle absolute paths in subdir
  2016-09-21 16:48 [PATCH] fetch2: handle absolute paths in subdir Ross Burton
@ 2016-09-21 21:09 ` Christopher Larson
  0 siblings, 0 replies; 2+ messages in thread
From: Christopher Larson @ 2016-09-21 21:09 UTC (permalink / raw)
  To: Ross Burton; +Cc: bitbake-devel

[-- Attachment #1: Type: text/plain, Size: 888 bytes --]

On Wed, Sep 21, 2016 at 9:48 AM, Ross Burton <ross.burton@intel.com> wrote:

> 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 <ross.burton@intel.com>
>

Looks good to me, thanks for your work on this.
-- 
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

[-- Attachment #2: Type: text/html, Size: 1366 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-21 21:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-21 16:48 [PATCH] fetch2: handle absolute paths in subdir Ross Burton
2016-09-21 21:09 ` Christopher Larson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.