From: Daniel Dunbar Date: Thu, 15 Nov 2012 20:24:52 +0000 (+0000) Subject: PathV2: Fix a possible infinite loop. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=71e5ea88604161e2e1effe20486ab3bcb363645f;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168081 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc index d04f590f87e..05fd924960e 100644 --- a/lib/Support/Unix/PathV2.inc +++ b/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) {