From 661b2ddcb5e0326ca3e2c1fc88c29d969d393d16 Mon Sep 17 00:00:00 2001 From: lixiang_yewu Date: Mon, 9 Oct 2023 02:44:13 +0000 Subject: [PATCH] update src/elf_check_elf.c. Signed-off-by: lixiang_yewu update src/elf_check_elf.c. Signed-off-by: lixiang_yewu --- src/elf_check_elf.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/elf_check_elf.c b/src/elf_check_elf.c index 4eeaed7..faf7ad9 100644 --- a/src/elf_check_elf.c +++ b/src/elf_check_elf.c @@ -22,7 +22,11 @@ static void check_bss_addr(elf_file_t *out_ef) { - // in kernel, bss addr = data segment + filesize + if (out_ef == NULL) { + si_panic("Null pointer: out_ef in check_bss_addr\n"); + return; + } + // in kernel, bss addr = data segment + filesize Elf64_Shdr *sec = elf_find_section_by_name(out_ef, ".bss"); Elf64_Phdr *p = out_ef->data_Phdr; @@ -33,6 +37,10 @@ static void check_bss_addr(elf_file_t *out_ef) static void check_data_section_addr(elf_file_t *out_ef) { + if (out_ef == NULL) { + si_panic("Null pointer: out_ef in check_data_section_addr\n"); + return; + } Elf64_Shdr *sec = elf_find_section_by_name(out_ef, ".data"); // .data section addr align 2M @@ -62,6 +70,10 @@ static bool is_dynsym_valid(Elf64_Sym *sym, const char *name) static void check_rela_dyn(elf_link_t *elf_link, elf_file_t *out_ef) { + if (elf_link == NULL || out_ef == NULL) { + si_panic("Null pointer: elf_link or out_ef in check_rela_dyn\n"); + return; + } if (is_share_mode(elf_link)) { return; } @@ -93,6 +105,10 @@ static void check_rela_dyn(elf_link_t *elf_link, elf_file_t *out_ef) static void check_dynamic(elf_link_t *elf_link, elf_file_t *out_ef) { + if (elf_link == NULL || out_ef == NULL) { + si_panic("Null pointer: elf_link or out_ef in check_dynamic\n"); + return; + } Elf64_Dyn *dyn_arr = NULL; Elf64_Dyn *dyn = NULL; int dyn_count = 0; @@ -116,7 +132,11 @@ static void check_dynamic(elf_link_t *elf_link, elf_file_t *out_ef) // .rela.init_array no use, .init_array will set by .rely.dyn in ld.so static void check_func(elf_file_t *out_ef, unsigned long func_point) -{ +{ + if (out_ef == NULL) { + si_panic("Null pointer: out_ef in check_func\n"); + return; + } Elf64_Rela *rela = elf_get_rela_by_addr(out_ef, func_point); if (rela == NULL) { si_panic("not fonud r_offset in .rely.dyn, %lx\n", func_point); @@ -139,6 +159,10 @@ static void check_func(elf_file_t *out_ef, unsigned long func_point) static void check_func_array(elf_file_t *out_ef, char *sec_name) { + if (out_ef == NULL) { + si_panic("Null pointer: out_ef in check_func_array\n"); + return; + } SI_LOG_DEBUG("check func addr in %s:\n", sec_name); Elf64_Shdr *sec = elf_find_section_by_name(out_ef, sec_name); int count = sec->sh_size / sizeof(unsigned long); @@ -151,12 +175,20 @@ static void check_func_array(elf_file_t *out_ef, char *sec_name) // .init_array .fini_array is func addr static void check_init_fini_array(elf_file_t *out_ef) { + if (out_ef == NULL) { + si_panic("Null pointer: out_ef in check_init_fini_array\n"); + return; + } check_func_array(out_ef, ".init_array"); check_func_array(out_ef, ".fini_array"); } void elf_check_elf(elf_link_t *elf_link) { + if (elf_link == NULL) { + si_panic("Null pointer: elf_link in elf_check_elf\n"); + return; + } elf_file_t *out_ef = &elf_link->out_ef; check_bss_addr(out_ef); check_data_section_addr(out_ef); -- Gitee