From 695a05dc5dd4564169df63213cb8b99dc2b6c31d Mon Sep 17 00:00:00 2001 From: Semi Malinen Date: Thu, 30 Oct 2014 14:29:33 +0200 Subject: [PATCH] Do not index past the end of the chain table --- elfio/elfio_symbols.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elfio/elfio_symbols.hpp b/elfio/elfio_symbols.hpp index b893e2b..aefbdde 100644 --- a/elfio/elfio_symbols.hpp +++ b/elfio/elfio_symbols.hpp @@ -88,13 +88,15 @@ class symbol_section_accessor if ( 0 != get_hash_table_index() ) { Elf_Word nbucket = *(Elf_Word*)hash_section->get_data(); + Elf_Word nchain = *(Elf_Word*)( hash_section->get_data() + + sizeof( Elf_Word ) ); Elf_Word val = elf_hash( (const unsigned char*)name.c_str() ); Elf_Word y = *(Elf_Word*)( hash_section->get_data() + ( 2 + val % nbucket ) * sizeof( Elf_Word ) ); std::string str; get_symbol( y, str, value, size, bind, type, section_index, other ); - while ( str != name && STN_UNDEF != y ) { + while ( str != name && STN_UNDEF != y && y < nchain ) { y = *(Elf_Word*)( hash_section->get_data() + ( 2 + nbucket + y ) * sizeof( Elf_Word ) ); get_symbol( y, str, value, size, bind, type, section_index, other );