[llvm-commits] [llvm] r90082 - /llvm/trunk/lib/System/Unix/Path.inc

Kovarththanan Rajaratnam kovarththanan.rajaratnam at gmail.com
Sun Nov 29 09:19:49 PST 2009


Author: krj
Date: Sun Nov 29 11:19:48 2009
New Revision: 90082

URL: http://llvm.org/viewvc/llvm-project?rev=90082&view=rev
Log:
This patch ensures that Path::GetMainExecutable is able to handle the
case where realpath() fails. When this occurs we segfault trying to
create a std::string from a NULL pointer.

Fixes PR5635.

Modified:
    llvm/trunk/lib/System/Unix/Path.inc

Modified: llvm/trunk/lib/System/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Path.inc?rev=90082&r1=90081&r2=90082&view=diff

==============================================================================
--- llvm/trunk/lib/System/Unix/Path.inc (original)
+++ llvm/trunk/lib/System/Unix/Path.inc Sun Nov 29 11:19:48 2009
@@ -348,7 +348,9 @@
   uint32_t size = sizeof(exe_path);
   if (_NSGetExecutablePath(exe_path, &size) == 0) {
     char link_path[MAXPATHLEN];
-    return Path(std::string(realpath(exe_path, link_path)));
+    if (realpath(exe_path, link_path))
+      return Path(std::string(link_path));
+    return Path();
   }
 #elif defined(__FreeBSD__)
   char exe_path[PATH_MAX];
@@ -370,7 +372,9 @@
   // If the filename is a symlink, we need to resolve and return the location of
   // the actual executable.
   char link_path[MAXPATHLEN];
-  return Path(std::string(realpath(DLInfo.dli_fname, link_path)));
+  if (realpath(DLInfo.dli_fname, link_path))
+    return Path(std::string(link_path));
+  return Path();
 #endif
   return Path();
 }





More information about the llvm-commits mailing list