linux_dumper: Always map ELF file from offset 0

Functions such as FindElfSection and FindElfSegments that inspect
the ELF header expect a pointer to the first byte of the file.
IsValidElf() checks for the ELF magic number at offset 0.
Thus, we must map ELF object files from offset 0.

Change-Id: Icebfb46229a04019f57a7ec07844257b98ceb278
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4674337
Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Marc Gonzalez 2023-08-01 18:24:19 +02:00 committed by Mike Frysinger
parent 0d0354463e
commit d10ef76a38

View file

@ -346,7 +346,7 @@ LinuxDumper::ElfFileIdentifierForMapping(const MappingInfo& mapping,
return false; return false;
bool filename_modified = HandleDeletedFileInMapping(filename); bool filename_modified = HandleDeletedFileInMapping(filename);
MemoryMappedFile mapped_file(filename, mapping.offset); MemoryMappedFile mapped_file(filename, 0);
if (!mapped_file.data() || mapped_file.size() < SELFMAG) if (!mapped_file.data() || mapped_file.size() < SELFMAG)
return false; return false;
@ -459,7 +459,7 @@ bool ElfFileSoName(const LinuxDumper& dumper,
if (!dumper.GetMappingAbsolutePath(mapping, filename)) if (!dumper.GetMappingAbsolutePath(mapping, filename))
return false; return false;
MemoryMappedFile mapped_file(filename, mapping.offset); MemoryMappedFile mapped_file(filename, 0);
if (!mapped_file.data() || mapped_file.size() < SELFMAG) { if (!mapped_file.data() || mapped_file.size() < SELFMAG) {
// mmap failed // mmap failed
return false; return false;