[cmake-developers] Fix divide by zero error in ELF Dynamic Section parsing

Ty Smith tyfighter at gmail.com
Thu Nov 19 12:04:34 EST 2015


I've attached a patch made when I encountered a divide by zero error
when compiling with the latest CMake release.
This can happen with GCC for certain platforms; here it was MIPS.

Thanks,
Ty

-------------- next part --------------
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx
index d062987..37dd328 100644
--- a/Source/cmELF.cxx
+++ b/Source/cmELF.cxx
@@ -567,8 +567,14 @@ bool cmELFInternalImpl<Types>::LoadDynamicSection()
     return true;
     }

-  // Allocate the dynamic section entries.
+  // If there are no entries we are done.
   ELF_Shdr const& sec = this->SectionHeaders[this->DynamicSectionIndex];
+  if(sec.sh_entsize == 0)
+    {
+    return false;
+    }
+
+  // Allocate the dynamic section entries.
   int n = static_cast<int>(sec.sh_size / sec.sh_entsize);
   this->DynamicSectionEntries.resize(n);



More information about the cmake-developers mailing list