[v2,7/8] net/nfp: fix dereference after null check
Checks
Commit Message
From: Peng Zhang <peng.zhang@corigine.com>
CI found in the logic of 'nfp_elf_read_first_symtab()' has
dereference after null check problem.
Coverity issue: 415042
Fixes: c82ca09c441c ("net/nfp: add ELF module")
Cc: stable@dpdk.org
Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
drivers/net/nfp/nfpcore/nfp_elf.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
@@ -898,9 +898,10 @@ nfp_elf_read_first_symtab(struct nfp_elf *ectx)
size_t idx;
uint32_t sh_type;
uint64_t sh_size;
- struct nfp_elf_elf64_shdr *sec;
+ struct nfp_elf_elf64_shdr *sec = NULL;
- for (idx = 0, sec = ectx->shdrs; idx < ectx->shdrs_cnt; idx++, sec++) {
+ for (idx = 0; idx < ectx->shdrs_cnt; idx++) {
+ sec = &ectx->shdrs[idx];
if (sec != NULL) {
sh_type = rte_le_to_cpu_32(sec->sh_type);
if (sh_type == NFP_ELF_SHT_SYMTAB)
@@ -908,6 +909,9 @@ nfp_elf_read_first_symtab(struct nfp_elf *ectx)
}
}
+ if (sec == NULL)
+ return -EINVAL;
+
sh_size = rte_le_to_cpu_64(sec->sh_size);
if (idx < ectx->shdrs_cnt && sh_type == NFP_ELF_SHT_SYMTAB) {