Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Add sanity checks for e_shentsize and e_shstrndx
Browse files Browse the repository at this point in the history
This helps us avoid situations when malformed elf-files
are mistakenly loaded, - which might result in unexpected
behavior.

Bug: http://b/30166532
Test: bionic-unit-tests --gtest_filter=dl*:Dl*
Change-Id: Idd6b4fa20e1d69a9f8d8391ba69c724d930fee51
  • Loading branch information
dimitry- committed Jul 22, 2016
1 parent 91f33cd commit c73eec1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions linker/linker_phdr.cpp
Expand Up @@ -245,6 +245,17 @@ bool ElfReader::VerifyElfHeader() {
return false;
}

if (header_.e_shentsize != sizeof(ElfW(Shdr))) {
DL_ERR("\"%s\" has unsupported e_shentsize: 0x%x (expected 0x%zx)",
name_.c_str(), header_.e_shentsize, sizeof(ElfW(Shdr)));
return false;
}

if (header_.e_shstrndx == 0) {
DL_ERR("\"%s\" has invalid e_shstrndx", name_.c_str());
return false;
}

return true;
}

Expand Down

0 comments on commit c73eec1

Please sign in to comment.