Skip to content

Commit bbe980d

Browse files
committedApr 23, 2018
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 llvm-svn: 330610
1 parent 1bc528c commit bbe980d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎llvm/lib/Object/SymbolSize.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ llvm::object::computeSymbolSizes(const ObjectFile &O) {
6666
Addresses.push_back(
6767
{O.symbol_end(), Address + Size, 0, getSectionID(O, Sec)});
6868
}
69+
70+
if (Addresses.empty())
71+
return Ret;
72+
6973
array_pod_sort(Addresses.begin(), Addresses.end(), compareAddress);
7074

7175
// Compute the size as the gap to the next symbol

‎llvm/test/tools/llvm-symbolizer/sym.test

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
RUN: llvm-symbolizer -print-address -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck %s
2121
RUN: llvm-symbolizer -inlining -print-address -pretty-print -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck --check-prefix="PRETTY" %s
22+
RUN: echo "0x1" > %t.input
23+
RUN: llvm-symbolizer -obj=%p/Inputs/zero < %t.input | FileCheck --check-prefix="ZERO" %s
2224

2325
#CHECK: some text
2426
#CHECK: 0x40054d
@@ -31,4 +33,6 @@ RUN: llvm-symbolizer -inlining -print-address -pretty-print -obj=%p/Inputs/addr.
3133
#PRETTY: (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7:0
3234
#PRETTY (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14:0
3335
#PRETTY: some text2
34-
36+
#
37+
#ZERO: ??
38+
#ZERO: ??:0:0

0 commit comments

Comments
 (0)
Please sign in to comment.