OSDN Git Service

Fix computeSymbolSizes SEGFAULT on invalid file
authorAdrian Prantl <aprantl@apple.com>
Mon, 23 Apr 2018 16:08:01 +0000 (16:08 +0000)
committerAdrian Prantl <aprantl@apple.com>
Mon, 23 Apr 2018 16:08:01 +0000 (16:08 +0000)
commit48c9175fe5260e03ecdb7a641ae06b813cc7701d
tree8e4effcf47fe08d44d3d0721a44baafbb7f2a666
parent7c20cc06694616487318aa9b6c908fd4983fa3ee
Fix computeSymbolSizes SEGFAULT on invalid file

We use llvm-symbolizer in some production systems, and we run it
against all possibly related files, including some that are not
ELF. We noticed that for some of those invalid files, llvm-symbolizer
would crash with SEGFAULT. Here is an example of such a file.

It is due to that in computeSymbolSizes, a loop uses condition

  for (unsigned I = 0, N = Addresses.size() - 1; I < N; ++I) {

where if Addresses.size() is 0, N would overflow and causing the loop
to access invalid memory.

Instead of patching the loop conditions, the commit makes so that the
function returns early if Addresses is empty.

Validated by checking that llvm-symbolizer no longer crashes.

Patch by Teng Qin!

Differential Revision: https://reviews.llvm.org/D44285

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330610 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Object/SymbolSize.cpp
test/tools/llvm-symbolizer/sym.test