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 | d614673bb8bee193341b3d516383be438915a9d4 (patch) | |
tree | 2b9192a731c9ffb56a520e206adc9ded1f83e725 /lib/System/Unix | |
parent | a76a7883b557c315f29dbf95155dd5ae0352fecf (diff) | |
download | external_llvm-d614673bb8bee193341b3d516383be438915a9d4.zip external_llvm-d614673bb8bee193341b3d516383be438915a9d4.tar.gz external_llvm-d614673bb8bee193341b3d516383be438915a9d4.tar.bz2 |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90082 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix')
-rw-r--r-- | lib/System/Unix/Path.inc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc index 4300d67..ec2ba7c 100644 --- a/lib/System/Unix/Path.inc +++ b/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(); } |