mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
LibELF: Fix stack overflow in ELFImage::relocations()
Thanks to braindead for finding the bug! :^)
This commit is contained in:
parent
0f42908073
commit
7ae7a60caa
2 changed files with 8 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "ELFImage.h"
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
|
#include <LibELF/ELFImage.h>
|
||||||
|
|
||||||
ELFImage::ELFImage(const u8* buffer)
|
ELFImage::ELFImage(const u8* buffer)
|
||||||
: m_buffer(buffer)
|
: m_buffer(buffer)
|
||||||
|
@ -194,14 +195,11 @@ const ELFImage::Relocation ELFImage::RelocationSection::relocation(unsigned inde
|
||||||
|
|
||||||
const ELFImage::RelocationSection ELFImage::Section::relocations() const
|
const ELFImage::RelocationSection ELFImage::Section::relocations() const
|
||||||
{
|
{
|
||||||
// FIXME: This is ugly.
|
StringBuilder builder;
|
||||||
char relocation_sectionName[128];
|
builder.append(".rel");
|
||||||
sprintf(relocation_sectionName, ".rel%s", name());
|
builder.append(name());
|
||||||
|
|
||||||
#ifdef ELFIMAGE_DEBUG
|
auto relocation_section = m_image.lookup_section(builder.to_string());
|
||||||
dbgprintf("looking for '%s'\n", relocation_sectionName);
|
|
||||||
#endif
|
|
||||||
auto relocation_section = m_image.lookup_section(relocation_sectionName);
|
|
||||||
if (relocation_section.type() != SHT_REL)
|
if (relocation_section.type() != SHT_REL)
|
||||||
return static_cast<const RelocationSection>(m_image.section(0));
|
return static_cast<const RelocationSection>(m_image.section(0));
|
||||||
|
|
||||||
|
@ -211,7 +209,7 @@ const ELFImage::RelocationSection ELFImage::Section::relocations() const
|
||||||
return static_cast<const RelocationSection>(relocation_section);
|
return static_cast<const RelocationSection>(relocation_section);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ELFImage::Section ELFImage::lookup_section(const char* name) const
|
const ELFImage::Section ELFImage::lookup_section(const String& name) const
|
||||||
{
|
{
|
||||||
if (auto it = m_sections.find(name); it != m_sections.end())
|
if (auto it = m_sections.find(name); it != m_sections.end())
|
||||||
return section((*it).value);
|
return section((*it).value);
|
||||||
|
|
|
@ -171,7 +171,7 @@ public:
|
||||||
|
|
||||||
// NOTE: Returns section(0) if section with name is not found.
|
// NOTE: Returns section(0) if section with name is not found.
|
||||||
// FIXME: I don't love this API.
|
// FIXME: I don't love this API.
|
||||||
const Section lookup_section(const char* name) const;
|
const Section lookup_section(const String& name) const;
|
||||||
|
|
||||||
bool is_executable() const { return header().e_type == ET_EXEC; }
|
bool is_executable() const { return header().e_type == ET_EXEC; }
|
||||||
bool is_relocatable() const { return header().e_type == ET_REL; }
|
bool is_relocatable() const { return header().e_type == ET_REL; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue