summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Windows
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2016-06-20 20:28:49 +0000
committerAaron Ballman <aaron@aaronballman.com>2016-06-20 20:28:49 +0000
commit3dd74b8edbf721932508dc8fe11fa99267aa0610 (patch)
treef1784266fc915f30c70a6906b7561868e4ab4be3 /llvm/lib/Support/Windows
parentada263dcd0a2a308942b96b073ca9fac762e09f7 (diff)
downloadbcm5719-llvm-3dd74b8edbf721932508dc8fe11fa99267aa0610.tar.gz
bcm5719-llvm-3dd74b8edbf721932508dc8fe11fa99267aa0610.zip
Fix a relatively nasty bug with fs::getPathFromOpenFD() on Windows. The GetFinalPathNameByHandle API does not behave as documented; if given a buffer that has enough space for the path but not the null terminator, the call will return the number of characters required *without* the null terminator (despite being documented otherwise) and it will not set GetLastError(). The result was that this function would return a bogus path and no error. Instead, ensure there is sufficient space for a null terminator (we already strip it off manually for compatibility with older versions of Windows).
llvm-svn: 273195
Diffstat (limited to 'llvm/lib/Support/Windows')
-rw-r--r--llvm/lib/Support/Windows/Path.inc17
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 5f588d7884e..8e5931ce6d8 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -821,11 +821,19 @@ std::error_code getPathFromOpenFD(int FD, SmallVectorImpl<char> &ResultPath) {
DWORD CharCount;
do {
+ // FIXME: We should be using the W version of this API and converting the
+ // resulting path to UTF-8 to handle non-ASCII file paths.
CharCount = ::GetFinalPathNameByHandleA(FileHandle, ResultPath.begin(),
- ResultPath.capacity(), FILE_NAME_NORMALIZED);
- if (CharCount <= ResultPath.capacity())
+ ResultPath.capacity(),
+ FILE_NAME_NORMALIZED);
+ if (CharCount < ResultPath.capacity())
break;
- ResultPath.reserve(CharCount);
+
+ // Reserve sufficient space for the path as well as the null character. Even
+ // though the API does not document that it is required, if we reserve just
+ // CharCount space, the function call will not store the resulting path and
+ // still report success.
+ ResultPath.reserve(CharCount + 1);
} while (true);
if (CharCount == 0)
@@ -833,7 +841,8 @@ std::error_code getPathFromOpenFD(int FD, SmallVectorImpl<char> &ResultPath) {
ResultPath.set_size(CharCount);
- // On earlier Windows releases, the character count includes the terminating null.
+ // On earlier Windows releases, the character count includes the terminating
+ // null.
if (ResultPath.back() == '\0')
ResultPath.pop_back();
OpenPOWER on IntegriCloud