From 6c9c35916ee94955c32adda69296e8db52150e4c Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Thu, 27 May 2021 12:26:56 +0200 Subject: [PATCH] ldelf: check presence of sym_tab in e32_relocate() Adds checks in e32_relocate() that sym_tab is assigned a symbol table before using it. This fixes coverity scan: CID 1501826 (#1 of 3): Explicit null dereferenced (FORWARD_NULL) CID 1501826 (#2 of 3): Explicit null dereferenced (FORWARD_NULL) CID 1501826 (#3 of 3): Explicit null dereferenced (FORWARD_NULL) Signed-off-by: Jens Wiklander --- ldelf/ta_elf_rel.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ldelf/ta_elf_rel.c b/ldelf/ta_elf_rel.c index 6c6f9d01508..93a5abe4e0c 100644 --- a/ldelf/ta_elf_rel.c +++ b/ldelf/ta_elf_rel.c @@ -367,16 +367,25 @@ static void e32_relocate(struct ta_elf *elf, unsigned int rel_sidx) break; case R_ARM_GLOB_DAT: case R_ARM_JUMP_SLOT: + if (!sym_tab) + err(TEE_ERROR_BAD_FORMAT, + "Missing symbol table"); e32_process_dyn_rel(sym_tab, num_syms, str_tab, str_tab_size, rel, where); break; case R_ARM_TLS_DTPMOD32: + if (!sym_tab) + err(TEE_ERROR_BAD_FORMAT, + "Missing symbol table"); mod = elf; e32_tls_get_module(sym_tab, num_syms, str_tab, str_tab_size, rel, &mod); *where = mod->tls_mod_id; break; case R_ARM_TLS_DTPOFF32: + if (!sym_tab) + err(TEE_ERROR_BAD_FORMAT, + "Missing symbol table"); e32_tls_resolve(sym_tab, num_syms, str_tab, str_tab_size, rel, &val); *where = val;