From 0ae6461b0b46eb0bd9aae92ddcfa7af86660196f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lothar=20Wa=C3=9Fmann?= Date: Fri, 9 Mar 2012 15:27:18 +0100 Subject: [PATCH] prevent crash in StELFFile::dumpSections() for certain section types --- tools/elftosb/common/StELFFile.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/elftosb/common/StELFFile.cpp b/tools/elftosb/common/StELFFile.cpp index 3b4b5686bb..09124d5e1f 100644 --- a/tools/elftosb/common/StELFFile.cpp +++ b/tools/elftosb/common/StELFFile.cpp @@ -505,8 +505,20 @@ void StELFFile::dumpSections() { const Elf32_Shdr & header = getSectionAtIndex(i); std::string name = getSectionNameAtIndex(header.sh_name); - - printf("%s: %s, 0x%08x, 0x%08x, 0x%08x, %d, %d, %d\n", name.c_str(), sectionTypes[header.sh_type], header.sh_addr, header.sh_offset, header.sh_size, header.sh_link, header.sh_info, header.sh_entsize); + + if (header.sh_type < sizeof(sectionTypes) / sizeof(sectionTypes[0])) { + printf("%s: %s, 0x%08x, 0x%08x, 0x%08x, %d, %d, %d\n", + name.c_str(), sectionTypes[header.sh_type], + header.sh_addr, header.sh_offset, + header.sh_size, header.sh_link, + header.sh_info, header.sh_entsize); + } else { + printf("%s: 0x%02x, 0x%08x, 0x%08x, 0x%08x, %d, %d, %d\n", + name.c_str(), header.sh_type, + header.sh_addr, header.sh_offset, + header.sh_size, header.sh_link, + header.sh_info, header.sh_entsize); + } } } -- 2.39.5