From a4375842bf6903620b3447da8c15250e19f75d76 Mon Sep 17 00:00:00 2001 From: Assaf Nativ Date: Sun, 3 Jun 2018 16:37:18 +0300 Subject: [PATCH] Safer sections iteration --- elf/elf.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/elf/elf.cc b/elf/elf.cc index 587329f..e808b17 100644 --- a/elf/elf.cc +++ b/elf/elf.cc @@ -103,8 +103,14 @@ elf::elf(const std::shared_ptr &l) // Load sections const void *sec_data = l->load(m->hdr.shoff, m->hdr.shentsize * m->hdr.shnum); + if (NULL == sec_data) { + return; + } for (unsigned i = 0; i < m->hdr.shnum; i++) { const void *sec = ((const char*)sec_data) + i * m->hdr.shentsize; + if (NULL == sec) { + continue; + } // XXX Circular reference. Maybe this should be // constructed on the fly? Canonicalizing the header // isn't super-cheap.