Patchwork [1/2] relocating the elf file only if the file size is larger than 64 byte

login
register
mail settings
Submitter rongqing.li@windriver.com
Date June 16, 2014, 6:46 a.m.
Message ID <1402901171-14424-1-git-send-email-rongqing.li@windriver.com>
Download mbox | patch
Permalink /patch/73835/
State Accepted
Commit ee0f647a2a38da6dae97770c6f36e6369637844b
Headers show

Comments

rongqing.li@windriver.com - June 16, 2014, 6:46 a.m.
From: Roy Li <rongqing.li@windriver.com>

When toolchain directory is changed to execute mode, some non-executable
files or empty files are sorted. This will lead to the below error:

	Extracting SDK...done
	Setting it up...Traceback (most recent call last):
	  File "..._SDK/relocate_sdk.py", line 208, in <module>
	    arch = get_arch()
	  File "..._SDK/relocate_sdk.py", line 39, in get_arch
	    ei_mag0,ei_mag1_3,ei_class = struct.unpack("<B3sB11x", e_ident)
	struct.error: unpack requires a string argument of length 16

To call get_arch and parse_elf_header, we should ensure the sorted file
is bigger than 64 byte.

Signed-off-by: Roy Li <rongqing.li@windriver.com>
---
 scripts/relocate_sdk.py |   12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Patch

diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
index 05d9fd6..b2dd258 100755
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -224,12 +224,12 @@  for e in executables_list:
 
     # Save old size and do a size check at the end. Just a safety measure.
     old_size = os.path.getsize(e)
-
-    arch = get_arch()
-    if arch:
-        parse_elf_header()
-        change_interpreter(e)
-        change_dl_sysdirs()
+    if old_size >= 64:
+        arch = get_arch()
+        if arch:
+            parse_elf_header()
+            change_interpreter(e)
+            change_dl_sysdirs()
 
     """ change permissions back """
     if perms: