[PATCH] D39185: [llvm-dwarfdump] - Fix array out of bounds access crash.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 23 09:22:14 PDT 2017


George Rimar via Phabricator <reviews at reviews.llvm.org> writes:

> Index: tools/llvm-dwarfdump/llvm-dwarfdump.cpp
> ===================================================================
> --- tools/llvm-dwarfdump/llvm-dwarfdump.cpp
> +++ tools/llvm-dwarfdump/llvm-dwarfdump.cpp
> @@ -280,9 +280,9 @@
>  /// Print only DIEs that have a certain name.
>  static void filterByName(const StringSet<> &Names,
>                           DWARFContext::cu_iterator_range CUs, raw_ostream &OS) {
> -  for (const auto &CU : CUs)
> -    for (const auto &Entry : CU->dies()) {
> -      DWARFDie Die = {CU.get(), &Entry};
> +  for (const auto &CU : CUs) {
> +    for (unsigned I = 0, E = CU->getNumDIEs(); I != E; ++I) {
> +      DWARFDie Die = CU->getDIEAtIndex(I);

Why can't this remain a range loop?

> Index: lib/DebugInfo/DWARF/DWARFUnit.cpp
> ===================================================================
> --- lib/DebugInfo/DWARF/DWARFUnit.cpp
> +++ lib/DebugInfo/DWARF/DWARFUnit.cpp
> @@ -425,7 +425,7 @@
>    const uint32_t ParentDepth = Depth - 1;
>    for (uint32_t I = getDIEIndex(Die) - 1; I > 0; --I) {
>      if (DieArray[I].getDepth() == ParentDepth)
> -      return DWARFDie(this, &DieArray[I]);
> +      return DWARFDie(this, {DieArray.data() + I, DieArray.size() - I});

This is a .slice(), no? The same for a few other places.

Cheers,
Rafael


More information about the llvm-commits mailing list