summaryrefslogtreecommitdiffstats
path: root/scripts/relocate_sdk.py
diff options
context:
space:
mode:
authorJuro Bystricky <juro.bystricky@intel.com>2016-03-30 17:13:54 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-03-31 23:01:37 +0100
commit4dde12f17b5c0e8b029272284b9013cdef5ccd60 (patch)
tree82a26e550e0f27dbd9a1426837d693b6ef5ee141 /scripts/relocate_sdk.py
parent22bd875a5a7a5ccd8021c17ebb9b3eab2226f190 (diff)
downloadpoky-4dde12f17b5c0e8b029272284b9013cdef5ccd60.tar.gz
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] (From OE-Core rev: 4d949da965a99ab33798af49e5584c8bb9f0f626) Signed-off-by: Juro Bystricky <juro.bystricky@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/relocate_sdk.py')
-rwxr-xr-xscripts/relocate_sdk.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
index ceca1f2563..99fca86a12 100755
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -112,7 +112,7 @@ def change_interpreter(elf_file_name):
112 f.write(dl_path) 112 f.write(dl_path)
113 break 113 break
114 114
115def change_dl_sysdirs(): 115def change_dl_sysdirs(elf_file_name):
116 if arch == 32: 116 if arch == 32:
117 sh_fmt = "<IIIIIIIIII" 117 sh_fmt = "<IIIIIIIIII"
118 else: 118 else:
@@ -156,6 +156,11 @@ def change_dl_sysdirs():
156 elif name == b(".ldsocache"): 156 elif name == b(".ldsocache"):
157 ldsocache_path = f.read(sh_size) 157 ldsocache_path = f.read(sh_size)
158 new_ldsocache_path = old_prefix.sub(new_prefix, ldsocache_path) 158 new_ldsocache_path = old_prefix.sub(new_prefix, ldsocache_path)
159 new_ldsocache_path = new_ldsocache_path.rstrip(b("\0"))
160 if (len(new_ldsocache_path) >= sh_size):
161 print("ERROR: could not relocate %s, .ldsocache section size = %i and %i is needed." \
162 % (elf_file_name, sh_size, len(new_ldsocache_path)))
163 sys.exit(-1)
159 # pad with zeros 164 # pad with zeros
160 new_ldsocache_path += b("\0") * (sh_size - len(new_ldsocache_path)) 165 new_ldsocache_path += b("\0") * (sh_size - len(new_ldsocache_path))
161 # write it back 166 # write it back
@@ -167,6 +172,10 @@ def change_dl_sysdirs():
167 path = f.read(4096) 172 path = f.read(4096)
168 new_path = old_prefix.sub(new_prefix, path) 173 new_path = old_prefix.sub(new_prefix, path)
169 new_path = new_path.rstrip(b("\0")) 174 new_path = new_path.rstrip(b("\0"))
175 if (len(new_path) >= 4096):
176 print("ERROR: could not relocate %s, max path size = 4096 and %i is needed." \
177 % (elf_file_name, len(new_path)))
178 sys.exit(-1)
170 # pad with zeros 179 # pad with zeros
171 new_path += b("\0") * (4096 - len(new_path)) 180 new_path += b("\0") * (4096 - len(new_path))
172 #print "Changing %s to %s at %s" % (str(path), str(new_path), str(offset)) 181 #print "Changing %s to %s at %s" % (str(path), str(new_path), str(offset))
@@ -241,7 +250,7 @@ for e in executables_list:
241 if arch: 250 if arch:
242 parse_elf_header() 251 parse_elf_header()
243 change_interpreter(e) 252 change_interpreter(e)
244 change_dl_sysdirs() 253 change_dl_sysdirs(e)
245 254
246 """ change permissions back """ 255 """ change permissions back """
247 if perms: 256 if perms: