[PATCH] D25327: [ELF] - Do not crash on invalid size of dynamic section.
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 6 10:49:45 PDT 2016
On 6 October 2016 at 11:09, George Rimar <grimar at accesssoftek.com> wrote:
> grimar created this revision.
> grimar added reviewers: ruiu, rafael, davide.
> grimar added subscribers: llvm-commits, grimar, evgeny777.
>
> Previously if sh_size of dynamic section was broken,
> lld may crash. Or even may not crash if used 32 bits host.
> (then value may be truncated to 32 bits when doing pointer arithmetic
> and could be just zero).
> Patch fixes the issue.
>
>
> https://reviews.llvm.org/D25327
>
> Files:
> ELF/InputFiles.cpp
> test/ELF/invalid/Inputs/dynamic-section-sh_size.elf
> test/ELF/invalid/dynamic-section-size.s
>
>
> Index: test/ELF/invalid/dynamic-section-size.s
> ===================================================================
> --- test/ELF/invalid/dynamic-section-size.s
> +++ test/ELF/invalid/dynamic-section-size.s
> @@ -0,0 +1,4 @@
> +## dynamic-section-sh_size.elf has incorrect sh_size of dynamic section.
> +# RUN: not ld.lld %p/Inputs/dynamic-section-sh_size.elf -o %t2 2>&1 | \
> +# RUN: FileCheck %s
> +# CHECK: Invalid data was encountered while parsing the file
> Index: ELF/InputFiles.cpp
> ===================================================================
> --- ELF/InputFiles.cpp
> +++ ELF/InputFiles.cpp
> @@ -518,11 +518,11 @@
>
> if (!DynamicSec)
> return;
> - auto *Begin =
> - reinterpret_cast<const Elf_Dyn *>(Obj.base() + DynamicSec->sh_offset);
> - const Elf_Dyn *End = Begin + DynamicSec->sh_size / sizeof(Elf_Dyn);
>
> - for (const Elf_Dyn &Dyn : make_range(Begin, End)) {
> + ArrayRef<Elf_Dyn> Arr =
> + check(Obj.template getSectionContentsAsArray<Elf_Dyn>(DynamicSec),
> + getFilename(this));
> + for (const Elf_Dyn &Dyn : Ar
Test for the filename in the test since you are including it in the error.
LGTM with that.
Cheers,
Rafael
More information about the llvm-commits
mailing list