diff options
| author | Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com> | 2009-11-29 17:19:48 +0000 |
|---|---|---|
| committer | Kovarththanan Rajaratnam <kovarththanan.rajaratnam@gmail.com> | 2009-11-29 17:19:48 +0000 |
| commit | 4b9f0b6720b040376398a7a12da908f0d21d23fb (patch) | |
| tree | de45a06a2e3a7c5775fbd6608440d6b0ad8d0807 /llvm/lib/System | |
| parent | d6ee467473a5c237c67bc28affd64853590fca52 (diff) | |
| download | bcm5719-llvm-4b9f0b6720b040376398a7a12da908f0d21d23fb.tar.gz bcm5719-llvm-4b9f0b6720b040376398a7a12da908f0d21d23fb.zip | |
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.
llvm-svn: 90082
Diffstat (limited to 'llvm/lib/System')
| -rw-r--r-- | llvm/lib/System/Unix/Path.inc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/System/Unix/Path.inc b/llvm/lib/System/Unix/Path.inc index 4300d6719b3..ec2ba7cd9c3 100644 --- a/llvm/lib/System/Unix/Path.inc +++ b/llvm/lib/System/Unix/Path.inc @@ -348,7 +348,9 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { 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 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { // 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(); } |

