From 15067a64a926e83d33ee1b9dbabb49d426b0e061 Mon Sep 17 00:00:00 2001 From: Juergen Ributzka Date: Fri, 19 Dec 2014 02:31:01 +0000 Subject: [PATCH] [Object] Don't crash on empty export lists. Summary: This fixes the exports iterator if the export list is empty. Reviewers: Bigcheese, kledzik Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6732 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224563 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/MachOObjectFile.cpp | 5 ++++- test/Object/Inputs/macho-no-exports.dylib | Bin 0 -> 4208 bytes test/Object/objdump-export-list.test | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100755 test/Object/Inputs/macho-no-exports.dylib create mode 100644 test/Object/objdump-export-list.test diff --git a/lib/Object/MachOObjectFile.cpp b/lib/Object/MachOObjectFile.cpp index fd086af6d52..92981fe6b7e 100644 --- a/lib/Object/MachOObjectFile.cpp +++ b/lib/Object/MachOObjectFile.cpp @@ -1640,7 +1640,10 @@ void ExportEntry::moveNext() { iterator_range MachOObjectFile::exports(ArrayRef Trie) { ExportEntry Start(Trie); - Start.moveToFirst(); + if (Trie.size() == 0) + Start.moveToEnd(); + else + Start.moveToFirst(); ExportEntry Finish(Trie); Finish.moveToEnd(); diff --git a/test/Object/Inputs/macho-no-exports.dylib b/test/Object/Inputs/macho-no-exports.dylib new file mode 100755 index 0000000000000000000000000000000000000000..6e1be6ca97e67b5281475a295532847b3be69324 GIT binary patch literal 4208 zcmeHLyGjF55IxbTA&FpNq1dR1_+S&eSXhV{*kBOB6lvsQ+(iTCL3RU4mqx$A+TO-e z@Ds#8@DJ>)f{14}dy^0&SX$hHvpaL{%%5QDTCfN=aJ4u zzU5m9;)EDy!}E!Z-#L!Ac5_nc%Qy8qkvJsC}0#Y3K#{9 z0!9I&fKk9GU=;Wt3UuF+vaatDdi|UyC&O)ooLmpcikKK$2^m7J4uS&~>RK#=3$vp< PzgbeHa@BDgk_CJN(&a!H literal 0 HcmV?d00001 diff --git a/test/Object/objdump-export-list.test b/test/Object/objdump-export-list.test new file mode 100644 index 00000000000..74344c1c2e2 --- /dev/null +++ b/test/Object/objdump-export-list.test @@ -0,0 +1,4 @@ +RUN: llvm-objdump -exports-trie %p/Inputs/macho-no-exports.dylib | FileCheck %s + +; Test that we don't crash with an empty export list. +CHECK: macho-no-exports.dylib: file format Mach-O 64-bit x86-64 -- 2.11.0