diff options
author | Daniel Dunbar <daniel@zuster.org> | 2012-11-15 20:24:52 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2012-11-15 20:24:52 +0000 |
commit | 61d59f29595345ce23b93bc6977657be5959214c (patch) | |
tree | 5acf40db8084e3059218c8bb206b386f5f118088 /llvm/lib/Support/Unix | |
parent | 19bc88c3d425a18ad1a9e16127856b88b62058fa (diff) | |
download | bcm5719-llvm-61d59f29595345ce23b93bc6977657be5959214c.tar.gz bcm5719-llvm-61d59f29595345ce23b93bc6977657be5959214c.zip |
PathV2: Fix a possible infinite loop.
- The code could infinite loop trying to create unique files, if the directory
containing the unique file exists, but open() calls on non-existent files in
the path return ENOENT. This is true on the /dev/fd filesystem, for example.
- Will add a clang side test case for this.
llvm-svn: 168081
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r-- | llvm/lib/Support/Unix/PathV2.inc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc index d04f590f87e..05fd924960e 100644 --- a/llvm/lib/Support/Unix/PathV2.inc +++ b/llvm/lib/Support/Unix/PathV2.inc @@ -424,9 +424,10 @@ rety_open_create: // If the file existed, try again, otherwise, error. if (errno == errc::file_exists) goto retry_random_path; - // The path prefix doesn't exist. - if (errno == errc::no_such_file_or_directory) { - StringRef p(RandomPath.begin(), RandomPath.size()); + // If path prefix doesn't exist, try to create it. + if (errno == errc::no_such_file_or_directory && + !exists(path::parent_path(RandomPath))) { + StringRef p(RandomPath); SmallString<64> dir_to_create; for (path::const_iterator i = path::begin(p), e = --path::end(p); i != e; ++i) { |