summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-02-28 00:38:19 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-02-28 00:38:19 +0000
commiteed2dc5769f81270371cceda3f3185bcecb2c599 (patch)
tree2dfd9b8d1b15e206d6c49f0004ce0cf721259b25 /llvm/lib/Support
parent1e55d8c6633337a9bc154880195a47ff69e6945c (diff)
downloadbcm5719-llvm-eed2dc5769f81270371cceda3f3185bcecb2c599.tar.gz
bcm5719-llvm-eed2dc5769f81270371cceda3f3185bcecb2c599.zip
[PathV2] In llvm::sys::fs::unique_file, make sure it doesn't fall into an infinite loop by constantly trying
to create the parent path. This can happen if the path is a relative filename and the current directory was removed. Thanks to Daniel D. for the hint in fixing it. llvm-svn: 176226
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/Unix/PathV2.inc8
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc
index 741f44a9db8..44b31b3202f 100644
--- a/llvm/lib/Support/Unix/PathV2.inc
+++ b/llvm/lib/Support/Unix/PathV2.inc
@@ -417,6 +417,10 @@ retry_random_path:
RandomPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15];
}
+ // Make sure we don't fall into an infinite loop by constantly trying
+ // to create the parent path.
+ bool TriedToCreateParent = false;
+
// Try to open + create the file.
rety_open_create:
int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode);
@@ -427,7 +431,9 @@ rety_open_create:
goto retry_random_path;
// If path prefix doesn't exist, try to create it.
if (SavedErrno == errc::no_such_file_or_directory &&
- !exists(path::parent_path(RandomPath))) {
+ !exists(path::parent_path(RandomPath)) &&
+ !TriedToCreateParent) {
+ TriedToCreateParent = true;
StringRef p(RandomPath);
SmallString<64> dir_to_create;
for (path::const_iterator i = path::begin(p),
OpenPOWER on IntegriCloud