[PATCH] src: fix DEREF_OF_NULL.RET.STAT in readelf.c in
Anton Moryakov
ant.v.moryakov@gmail.com
Thu Feb 13 16:33:12 GMT 2025
Static analyzer reported:
Return value of a function 'elf_strptr' is dereferenced at readelf.c:7171
without checking for NULL, but it is usually checked for this function (71/74).
Corrections explained:
- Added a NULL check for the scnname variable, which contains the result of
the elf_strptr call.
- The check is placed before the first use of scnname to prevent dereferencing
a NULL pointer.
Triggers found by static analyzer Svace.
Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
---
src/readelf.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/readelf.c b/src/readelf.c
index 6526db07..86ab3d37 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -7168,6 +7168,11 @@ print_debug_frame_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
return;
}
+ if (scnname == NULL)
+ {
+ error (0, 0, _("cannot get section name: %s"), elf_errmsg (-1));
+ return;
+ }
bool is_eh_frame = strcmp (scnname, ".eh_frame") == 0;
Elf_Data *data;
if (is_eh_frame)
--
2.30.2
More information about the Elfutils-devel
mailing list