From ee5b998f96be26a66976fd8afbe712e1ff43f411 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 9 Oct 2019 09:32:40 -0400 Subject: [PATCH] Fix: lttng-elf.c: dereferencing pointer before null check MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Coverity report: CID 1405899 (#1 of 1): Dereference before null check (REVERSE_INULL) check_after_deref: Null-checking elf suggests that it may be null, but it has already been dereferenced on all paths leading to the check. Reported-by: Coverity (1405899) Dereference before null check Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau --- src/common/lttng-elf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/common/lttng-elf.c b/src/common/lttng-elf.c index 91afcfdea..63e658177 100644 --- a/src/common/lttng-elf.c +++ b/src/common/lttng-elf.c @@ -646,13 +646,14 @@ char *lttng_elf_get_section_data(struct lttng_elf *elf, int ret; off_t section_offset; char *data; - const size_t max_alloc_size = min_t(size_t, MAX_SECTION_DATA_SIZE, - elf->file_size); + size_t max_alloc_size; if (!elf || !shdr) { goto error; } + max_alloc_size = min_t(size_t, MAX_SECTION_DATA_SIZE, elf->file_size); + section_offset = shdr->sh_offset; if (lseek(elf->fd, section_offset, SEEK_SET) < 0) { PERROR("Error seeking to section offset"); -- 2.34.1