diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2021-11-18 08:52:17 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2021-11-19 22:51:04 -0800 |
commit | 3b49aa72fe6ec0dd0aa0c1c41fb81e874dc789fa (patch) | |
tree | fadd20c349817ab7d33ad167a86beed15bfe3773 /src/corelib/plugin/qelfparser_p.cpp | |
parent | 892d5607d0b1c9e010ea10a1123e68741c46c21e (diff) |
Q{CoffPe,Elf,MachO}Parser: check that the magic string is present
Commit 2549a88ba2a48fa2bedce97dd71a2974c6f8840a changed the ELF and
Mach-O parsers to return an offset to the actual data header, not the
magic string, which we stopped searching for anyway. This commit brings
such a validity check back and adds it to the new COFF PE parser.
Change-Id: Iccb47e5527544b6fbd75fffd16b8b2252a76f179
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/plugin/qelfparser_p.cpp')
-rw-r--r-- | src/corelib/plugin/qelfparser_p.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/corelib/plugin/qelfparser_p.cpp b/src/corelib/plugin/qelfparser_p.cpp index 33af51d59b..6a83c94e20 100644 --- a/src/corelib/plugin/qelfparser_p.cpp +++ b/src/corelib/plugin/qelfparser_p.cpp @@ -712,13 +712,20 @@ static QLibraryScanResult scanSections(QByteArrayView data, const ErrorMaker &er if (name != QLatin1String(".qtmetadata")) continue; qEDebug << "found .qtmetadata section"; - if (IncludeValidityChecks && shdr->sh_flags & (SHF_WRITE | SHF_EXECINSTR)) { + if (shdr->sh_size < sizeof(QPluginMetaData::MagicHeader)) + return error(QLibrary::tr(".qtmetadata section is too small")); + + if (IncludeValidityChecks) { + QByteArrayView expectedMagic = QByteArrayView::fromArray(QPluginMetaData::MagicString); + QByteArrayView actualMagic = data.sliced(shdr->sh_offset, expectedMagic.size()); + if (expectedMagic != actualMagic) + return error(QLibrary::tr(".qtmetadata section has incorrect magic")); + if (shdr->sh_flags & SHF_WRITE) return error(QLibrary::tr(".qtmetadata section is writable")); - return error(QLibrary::tr(".qtmetadata section is executable")); + if (shdr->sh_flags & SHF_EXECINSTR) + return error(QLibrary::tr(".qtmetadata section is executable")); } - if (shdr->sh_size < sizeof(QPluginMetaData::MagicHeader)) - return error(QLibrary::tr("section .qtmetadata is too small")); return { qsizetype(shdr->sh_offset + sizeof(QPluginMetaData::MagicString)), qsizetype(shdr->sh_size - sizeof(QPluginMetaData::MagicString)) }; |