Commit 33f930e9 authored by hjk's avatar hjk
Browse files

elfreader: prevent out-of-bound reads when reading core file names



Change-Id: I2d1c2328d924acc8d1a8043625ad178b1c46ee6b
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 4a2787df
......@@ -327,6 +327,15 @@ QByteArray ElfReader::readSection(const QByteArray &name)
return QByteArray(mapper.start + section.offset, section.size);
}
static QByteArray cutout(const char *s)
{
QByteArray res(s, 80);
const int pos = res.indexOf('\0');
if (pos != -1)
res.resize(pos - 1);
return res;
}
QByteArray ElfReader::readCoreName(bool *isCore)
{
*isCore = false;
......@@ -345,15 +354,13 @@ QByteArray ElfReader::readCoreName(bool *isCore)
for (int i = 0, n = m_elfData.sectionHeaders.size(); i != n; ++i)
if (m_elfData.sectionHeaders.at(i).type == Elf_SHT_NOTE) {
const ElfSectionHeader &header = m_elfData.sectionHeaders.at(i);
const char *s = mapper.start + header.offset + 0x40;
return QByteArray(s);
return cutout(mapper.start + header.offset + 0x40);
}
for (int i = 0, n = m_elfData.programHeaders.size(); i != n; ++i)
if (m_elfData.programHeaders.at(i).type == Elf_PT_NOTE) {
const ElfProgramHeader &header = m_elfData.programHeaders.at(i);
const char *s = mapper.start + header.offset + 0xec;
return QByteArray(s);
return cutout(mapper.start + header.offset + 0xec);
}
return QByteArray();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment