From 798952b56170b46e17cbcd4d01b2ad3dea6e62db Mon Sep 17 00:00:00 2001 From: pancake Date: Sat, 10 Sep 2016 13:22:29 +0200 Subject: [PATCH] Fix #5723 - fix null deref in elf.destroy --- libr/bin/p/bin_elf.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/libr/bin/p/bin_elf.c b/libr/bin/p/bin_elf.c index 48bc24d99b..9834f7fb16 100644 --- a/libr/bin/p/bin_elf.c +++ b/libr/bin/p/bin_elf.c @@ -84,15 +84,17 @@ static int load(RBinFile *arch) { static int destroy(RBinFile *arch) { int i; ELFOBJ* eobj = arch->o->bin_obj; - for (i = 0; i < eobj->imports_by_ord_size; i++) { - RBinImport *imp = eobj->imports_by_ord[i]; - if (imp) { - free (imp->name); - free (imp); - eobj->imports_by_ord[i] = NULL; + if (eobj && eobj->imports_by_ord) { + for (i = 0; i < eobj->imports_by_ord_size; i++) { + RBinImport *imp = eobj->imports_by_ord[i]; + if (imp) { + free (imp->name); + free (imp); + eobj->imports_by_ord[i] = NULL; + } } + R_FREE (eobj->imports_by_ord); } - R_FREE (eobj->imports_by_ord); //static int r_bin_object_set_items(RBinFile *binfile, RBinObject *o) { Elf_(r_bin_elf_free) ((struct Elf_(r_bin_elf_obj_t)*)arch->o->bin_obj); return true;