Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid buffer overflow.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 17 Oct 2020 20:51:07 +0000 (22:51 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 17 Oct 2020 20:59:00 +0000 (22:59 +0200)
src/smpi/internals/smpi_memory.cpp

index 394dbb4..501f015 100644 (file)
@@ -55,10 +55,10 @@ void smpi_prepare_global_memory_segment()
 
 static void smpi_get_executable_global_size()
 {
-  char buffer[PATH_MAX];
-  const char* full_name = realpath(simgrid::xbt::binary_name.c_str(), buffer);
-  xbt_assert(full_name != nullptr, "Could not resolve real path of binary file '%s'",
-             simgrid::xbt::binary_name.c_str());
+  char* buffer = realpath(simgrid::xbt::binary_name.c_str(), nullptr);
+  xbt_assert(buffer != nullptr, "Could not resolve real path of binary file '%s'", simgrid::xbt::binary_name.c_str());
+  std::string full_name = buffer;
+  free(buffer);
 
   std::vector<simgrid::xbt::VmMap> map = simgrid::xbt::get_memory_map(getpid());
   for (auto i = map.begin(); i != map.end() ; ++i) {