[oe-commits] [openembedded-core] 11/13: relocate_sdk: additional error checks

git at git.openembedded.org git at git.openembedded.org
Thu Mar 31 11:58:44 UTC 2016


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

commit 1b9928687d84abe2fb36030b1f55533ced105a8e
Author: Juro Bystricky <juro.bystricky at intel.com>
AuthorDate: Wed Mar 30 17:13:54 2016 -0700

    relocate_sdk: additional error checks
    
    When installing SDK in a non-default location and the path length
    of the SDK install location is longer than the path length of the
    default SDK location, relocation of .ldsochache section will overwrite
    file location outside of the .ldsocache section size.
    In addition, additional checks were added to ensure that any
    path in sections .gccrelocprefix and .ldsochache will not exceed
    the space allocated for it within the file, which would also result
    in file corruption.
    
    [YOCTO #9268]
    
    Signed-off-by: Juro Bystricky <juro.bystricky at intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 scripts/relocate_sdk.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
index ceca1f2..99fca86 100755
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -112,7 +112,7 @@ def change_interpreter(elf_file_name):
             f.write(dl_path)
             break
 
-def change_dl_sysdirs():
+def change_dl_sysdirs(elf_file_name):
     if arch == 32:
         sh_fmt = "<IIIIIIIIII"
     else:
@@ -156,6 +156,11 @@ def change_dl_sysdirs():
             elif name == b(".ldsocache"):
                 ldsocache_path = f.read(sh_size)
                 new_ldsocache_path = old_prefix.sub(new_prefix, ldsocache_path)
+                new_ldsocache_path = new_ldsocache_path.rstrip(b("\0"))
+                if (len(new_ldsocache_path) >= sh_size):
+                    print("ERROR: could not relocate %s, .ldsocache section size = %i and %i is needed." \
+                    % (elf_file_name, sh_size, len(new_ldsocache_path)))
+                    sys.exit(-1)
                 # pad with zeros
                 new_ldsocache_path += b("\0") * (sh_size - len(new_ldsocache_path))
                 # write it back
@@ -167,6 +172,10 @@ def change_dl_sysdirs():
                     path = f.read(4096)
                     new_path = old_prefix.sub(new_prefix, path)
                     new_path = new_path.rstrip(b("\0"))
+                    if (len(new_path) >= 4096):
+                        print("ERROR: could not relocate %s, max path size = 4096 and %i is needed." \
+                        % (elf_file_name, len(new_path)))
+                        sys.exit(-1)
                     # pad with zeros
                     new_path += b("\0") * (4096 - len(new_path))
                     #print "Changing %s to %s at %s" % (str(path), str(new_path), str(offset))
@@ -241,7 +250,7 @@ for e in executables_list:
         if arch:
             parse_elf_header()
             change_interpreter(e)
-            change_dl_sysdirs()
+            change_dl_sysdirs(e)
 
     """ change permissions back """
     if perms:

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


More information about the Openembedded-commits mailing list