summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-06-17 22:54:25 +0800
committerruki <[email protected]>2026-06-17 22:54:25 +0800
commitba2df770b8430a8f8e593d34dc05de051a59a1bd (patch)
treefc8725ce172872fc3ebc1c404e437a9e3bdee279
parentd74078e1b60b843de736716863ba4bc2b2a6500b (diff)
improve elf clean
-rw-r--r--core/src/xmake/binutils/elf/rpath.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/core/src/xmake/binutils/elf/rpath.c b/core/src/xmake/binutils/elf/rpath.c
index 539c8a018..576ec62cc 100644
--- a/core/src/xmake/binutils/elf/rpath.c
+++ b/core/src/xmake/binutils/elf/rpath.c
@@ -208,16 +208,29 @@ tb_bool_t xm_binutils_elf_rpath_clean(tb_stream_ref_t istream, tb_hize_t base_of
*
* @note we only need dynamic_offset/dynamic_size here (strtab is not used
* when removing entries by tag), so we do not require get_context to fully succeed.
+ *
+ * but the ELF header itself must be readable, otherwise we should not silently
+ * treat a truncated/corrupted file as a no-op success below.
*/
xm_elf_context_t ctx;
tb_memset(&ctx, 0, sizeof(ctx));
+ tb_bool_t header_ok = tb_false;
if (ident[XM_ELF_EI_CLASS] == XM_ELF_CLASS32) {
- xm_binutils_elf_get_context_32(istream, base_offset, &ctx);
+ xm_elf32_header_t header;
+ if (xm_binutils_elf_read_header_32(istream, base_offset, &header)) {
+ header_ok = tb_true;
+ xm_binutils_elf_get_context_32(istream, base_offset, &ctx);
+ }
} else if (ident[XM_ELF_EI_CLASS] == XM_ELF_CLASS64) {
- xm_binutils_elf_get_context_64(istream, base_offset, &ctx);
+ xm_elf64_header_t header;
+ if (xm_binutils_elf_read_header_64(istream, base_offset, &header)) {
+ header_ok = tb_true;
+ xm_binutils_elf_get_context_64(istream, base_offset, &ctx);
+ }
} else {
break;
}
+ if (!header_ok) break;
/* no .dynamic section? e.g. a fully static executable (-static),
* there is no rpath/runpath to clean, so just treat it as a no-op success.