aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2007-10-25 10:38:44 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2007-10-25 10:38:44 +0000
commitbbfee22b6a4c8ab450715de1d2bf9c1596e58e33 (patch)
treecac7177efdc94dbcad3a54af18c3c0de9c430dd4
parent3cc42cfa904b5af43b5ff9c0bbdba0c38ebe206f (diff)
downloadpaludis-bbfee22b6a4c8ab450715de1d2bf9c1596e58e33.tar.gz
paludis-bbfee22b6a4c8ab450715de1d2bf9c1596e58e33.tar.xz
Don't divide by zero or look past the end of a string.
-rw-r--r--src/clients/reconcilio/littlelf/elf_dynamic_section.cc19
-rw-r--r--src/clients/reconcilio/littlelf/elf_relocation_section.cc13
-rw-r--r--src/clients/reconcilio/littlelf/elf_sections.cc2
-rw-r--r--src/clients/reconcilio/littlelf/elf_symbol_section.cc13
4 files changed, 29 insertions, 18 deletions
diff --git a/src/clients/reconcilio/littlelf/elf_dynamic_section.cc b/src/clients/reconcilio/littlelf/elf_dynamic_section.cc
index 613bc98..18aa4eb 100644
--- a/src/clients/reconcilio/littlelf/elf_dynamic_section.cc
+++ b/src/clients/reconcilio/littlelf/elf_dynamic_section.cc
@@ -233,15 +233,18 @@ DynamicSection<ElfType_>::DynamicSection(const typename ElfType_::SectionHeader
Section<ElfType_>(shdr),
PrivateImplementationPattern<DynamicSection>(new Implementation<DynamicSection>)
{
- stream.seekg(shdr.sh_offset, std::ios::beg);
- std::vector<typename ElfType_::DynamicEntry> tmp_entries(shdr.sh_size / shdr.sh_entsize);
- stream.read( reinterpret_cast<char *>(&tmp_entries.front()), shdr.sh_size );
-
- for (typename std::vector<typename ElfType_::DynamicEntry>::iterator i = tmp_entries.begin(); i != tmp_entries.end(); ++i)
+ if (0 != shdr.sh_entsize)
{
- paludis::tr1::shared_ptr<DynamicEntry<ElfType_> > instance(DynamicEntries<ElfType_>::get_instance()->get_entry(i->d_tag));
- instance->initialize(*i);
- _imp->dynamic_entries.push_back(instance);
+ stream.seekg(shdr.sh_offset, std::ios::beg);
+ std::vector<typename ElfType_::DynamicEntry> tmp_entries(shdr.sh_size / shdr.sh_entsize);
+ stream.read( reinterpret_cast<char *>(&tmp_entries.front()), shdr.sh_size );
+
+ for (typename std::vector<typename ElfType_::DynamicEntry>::iterator i = tmp_entries.begin(); i != tmp_entries.end(); ++i)
+ {
+ paludis::tr1::shared_ptr<DynamicEntry<ElfType_> > instance(DynamicEntries<ElfType_>::get_instance()->get_entry(i->d_tag));
+ instance->initialize(*i);
+ _imp->dynamic_entries.push_back(instance);
+ }
}
}
diff --git a/src/clients/reconcilio/littlelf/elf_relocation_section.cc b/src/clients/reconcilio/littlelf/elf_relocation_section.cc
index 530ee92..06e03ea 100644
--- a/src/clients/reconcilio/littlelf/elf_relocation_section.cc
+++ b/src/clients/reconcilio/littlelf/elf_relocation_section.cc
@@ -51,11 +51,14 @@ RelocationSection<ElfType_, Relocation_>::RelocationSection(const typename ElfTy
Section<ElfType_>(shdr),
PrivateImplementationPattern<RelocationSection>(new Implementation<RelocationSection>)
{
- std::vector<typename Relocation_::Type> relocations(shdr.sh_size / shdr.sh_entsize);
- stream.seekg(shdr.sh_offset, std::ios::beg);
- stream.read(reinterpret_cast<char *>(&relocations.front()), shdr.sh_size);
- for (typename std::vector<typename Relocation_::Type>::iterator i = relocations.begin(); i != relocations.end(); ++i)
- _imp->relocations.push_back(typename Relocation_::Entry(*i));
+ if (0 != shdr.sh_entsize)
+ {
+ std::vector<typename Relocation_::Type> relocations(shdr.sh_size / shdr.sh_entsize);
+ stream.seekg(shdr.sh_offset, std::ios::beg);
+ stream.read(reinterpret_cast<char *>(&relocations.front()), shdr.sh_size);
+ for (typename std::vector<typename Relocation_::Type>::iterator i = relocations.begin(); i != relocations.end(); ++i)
+ _imp->relocations.push_back(typename Relocation_::Entry(*i));
+ }
}
template <typename ElfType_, typename Relocation_>
diff --git a/src/clients/reconcilio/littlelf/elf_sections.cc b/src/clients/reconcilio/littlelf/elf_sections.cc
index 5e00621..c50419d 100644
--- a/src/clients/reconcilio/littlelf/elf_sections.cc
+++ b/src/clients/reconcilio/littlelf/elf_sections.cc
@@ -60,6 +60,8 @@ template <typename ElfType_>
std::string
StringSection<ElfType_>::get_string(typename ElfType_::Word index) const
{
+ if (index > _stringTable.size())
+ return "";
typename ElfType_::Word end(_stringTable.find_first_of('\0', index));
return _stringTable.substr(index, end-index);
}
diff --git a/src/clients/reconcilio/littlelf/elf_symbol_section.cc b/src/clients/reconcilio/littlelf/elf_symbol_section.cc
index 48faa08..1082c98 100644
--- a/src/clients/reconcilio/littlelf/elf_symbol_section.cc
+++ b/src/clients/reconcilio/littlelf/elf_symbol_section.cc
@@ -116,11 +116,14 @@ SymbolSection<ElfType_>::SymbolSection(const typename ElfType_::SectionHeader &
else if (shdr.sh_type == SHT_SYMTAB)
_type = "SYMTAB";
- std::vector<typename ElfType_::Symbol> symbols(shdr.sh_size / shdr.sh_entsize);
- stream.seekg(shdr.sh_offset, std::ios::beg);
- stream.read( reinterpret_cast<char *>(&symbols.front()), shdr.sh_size );
- for (typename std::vector<typename ElfType_::Symbol>::iterator i = symbols.begin(); i != symbols.end(); ++i)
- _imp->symbols.push_back(Symbol<ElfType_>(*i));
+ if (0 != shdr.sh_entsize)
+ {
+ std::vector<typename ElfType_::Symbol> symbols(shdr.sh_size / shdr.sh_entsize);
+ stream.seekg(shdr.sh_offset, std::ios::beg);
+ stream.read( reinterpret_cast<char *>(&symbols.front()), shdr.sh_size );
+ for (typename std::vector<typename ElfType_::Symbol>::iterator i = symbols.begin(); i != symbols.end(); ++i)
+ _imp->symbols.push_back(Symbol<ElfType_>(*i));
+ }
}
template <typename ElfType_>