Bug 2101 - When loading binary not compiled with the correct options, dce crashes
authorHajime Tazaki <tazaki@sfc.wide.ad.jp>
Mon, 01 Jun 2015 14:24:27 +0900
changeset 669 cb779a3844be
parent 668 06b23f4d262c
child 670 10182d62e5ae
Bug 2101 - When loading binary not compiled with the correct options, dce crashes
RELEASE_NOTES
model/dlm-loader-factory.cc
model/elf-cache.cc
--- a/RELEASE_NOTES	Sun May 31 21:50:17 2015 +0900
+++ b/RELEASE_NOTES	Mon Jun 01 14:24:27 2015 +0900
@@ -30,6 +30,7 @@
 - Bug 2085 - DCE build process crashes when using compiler flag for C++0x / C++11
 - Bug 1980 - setting UnixSocketFd socket buffer size
 - Bug 2129 - DCE-Linux simulations with heterogeneous nodes crash (some DCE-Linux and some ns3)
+- Bug 2101 - When loading binary not compiled with the correct options, dce crashes
 
 
 Release dce-1.6
--- a/model/dlm-loader-factory.cc	Sun May 31 21:50:17 2015 +0900
+++ b/model/dlm-loader-factory.cc	Mon Jun 01 14:24:27 2015 +0900
@@ -91,6 +91,13 @@
 {
   NS_LOG_FUNCTION (this << filename << flag);
   void *module = dlmopen (m_lmid, filename.c_str (), flag);
+  if (!module)
+    {
+      NS_LOG_UNCOND ("*** unable to open non-shared object file=" << filename << " ***");
+      NS_LOG_UNCOND ("dlerror() = " << dlerror ());
+      NS_ASSERT_MSG (false, "make it sure that DCE binrary file " << filename 
+                     << " was built with correct options: (CFLAGS=-fPIC, LDFLAGS=-pie -rdynamic)");
+    }
   m_loaded.push_back (module);
   return module;
 }
--- a/model/elf-cache.cc	Sun May 31 21:50:17 2015 +0900
+++ b/model/elf-cache.cc	Mon Jun 01 14:24:27 2015 +0900
@@ -163,6 +163,13 @@
 
   // find DYNAMIC and fill DataSection
   struct FileInfo fileInfo;
+
+  if (header->e_type != ET_DYN)
+    {
+      fileInfo.p_vaddr = -1;
+      return fileInfo;
+    }
+
   ElfW (Phdr) * pt_load_rw = 0;
   ElfW (Phdr) * pt_gnu_relro = 0;
   for (uint32_t i = 0; i < header->e_phnum; i++, phdr++)
@@ -257,6 +264,12 @@
   close (fd);
 
   struct FileInfo fileInfo = EditBuffer (buffer, selfId);
+  if (fileInfo.p_vaddr == -1)
+    {
+      NS_LOG_UNCOND ("*** unable to open non-shared object file=" << filename << " ***");
+      NS_ASSERT_MSG (false, "make it sure that DCE binrary file " << filename 
+                     << " was built with correct options: (CFLAGS=-fPIC, LDFLAGS=-pie -rdynamic)");
+    }
 
   // write back changes to hard disk
   retval = ::msync (buffer, size, MS_SYNC);