summaryrefslogtreecommitdiffstats
path: root/scripts/relocate_sdk.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/relocate_sdk.py')
-rwxr-xr-xscripts/relocate_sdk.py31
1 files changed, 16 insertions, 15 deletions
diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
index 992db5c47d..8c0fdb986a 100755
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -1,19 +1,8 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# Copyright (c) 2012 Intel Corporation
#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# SPDX-License-Identifier: GPL-2.0-only
#
# DESCRIPTION
# This script is called by the SDK installer script. It replaces the dynamic
@@ -103,6 +92,8 @@ def change_interpreter(elf_file_name):
fname.startswith(b("/lib32/")) or fname.startswith(b("/usr/lib32/")) or \
fname.startswith(b("/usr/lib32/")) or fname.startswith(b("/usr/lib64/")):
break
+ if p_filesz == 0:
+ break
if (len(new_dl_path) >= p_filesz):
print("ERROR: could not relocate %s, interp size = %i and %i is needed." \
% (elf_file_name, p_memsz, len(new_dl_path) + 1))
@@ -112,7 +103,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 +147,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
@@ -166,6 +162,11 @@ def change_dl_sysdirs():
while (offset + 4096) <= sh_size:
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))
@@ -240,7 +241,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: