[oe-commits] [openembedded-core] 05/06: recipetool: create: ensure meaningful error for malformed tarballs

git at git.openembedded.org git at git.openembedded.org
Wed Jul 19 13:02:32 UTC 2017


This is an automated email from the git hooks/post-receive script.

rpurdie pushed a commit to branch master-next
in repository openembedded-core.

commit 9fc1ded84c7a005ddd346dbac1e805db30c4885f
Author: Paul Eggleton <paul.eggleton at linux.intel.com>
AuthorDate: Wed Jul 19 12:07:17 2017 +0200

    recipetool: create: ensure meaningful error for malformed tarballs
    
    If you pointed recipetool at a URL that should be a tarball e.g.
    https://tls.mbed.org/download/start/mbedtls-2.4.2-apache.tgz but instead
    it returns an HTML page, we try to unpack it, gzip complains but the
    operation doesn't seem to fail - instead we just get back an empty
    source tree. Change the checks to account for this - if the source tree
    is empty, check if the downloaded file in DL_DIR looks like an HTML file
    and error accordingly if it is. If it's not, error out anyway because
    no source was unpacked and it should have been (otherwise we just
    blindly set up EXTERNALSRC for this which is pointless).
    
    Fixes an aspect of [YOCTO #11407].
    
    Signed-off-by: Paul Eggleton <paul.eggleton at linux.intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 scripts/lib/recipetool/create.py | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index 868d18b..4e965e4 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -465,10 +465,16 @@ def create_recipe(args):
                 srcsubdir = dirlist[0]
                 srctree = os.path.join(srctree, srcsubdir)
             else:
-                with open(singleitem, 'r', errors='surrogateescape') as f:
-                    if '<html' in f.read(100).lower():
-                        logger.error('Fetching "%s" returned a single HTML page - check the URL is correct and functional' % fetchuri)
-                        sys.exit(1)
+                check_single_file(dirlist[0], fetchuri)
+        elif len(dirlist) == 0:
+            if '/' in fetchuri:
+                fn = os.path.join(d.getVar('DL_DIR'), fetchuri.split('/')[-1])
+                if os.path.isfile(fn):
+                    check_single_file(fn, fetchuri)
+            # If we've got to here then there's no source so we might as well give up
+            logger.error('URL %s resulted in an empty source tree' % fetchuri)
+            sys.exit(1)
+
         if os.path.exists(os.path.join(srctree, '.gitmodules')) and srcuri.startswith('git://'):
             srcuri = 'gitsm://' + srcuri[6:]
             logger.info('Fetching submodules...')
@@ -815,6 +821,14 @@ def create_recipe(args):
 
     return 0
 
+def check_single_file(fn, fetchuri):
+    """Determine if a single downloaded file is something we can't handle"""
+    with open(fn, 'r', errors='surrogateescape') as f:
+        if '<html' in f.read(100).lower():
+            logger.error('Fetching "%s" returned a single HTML page - check the URL is correct and functional' % fetchuri)
+            sys.exit(1)
+
+
 def handle_license_vars(srctree, lines_before, handled, extravalues, d):
     licvalues = guess_license(srctree, d)
     lic_files_chksum = []

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list