From 96929fdd428aafc9ed3d3a2070627fabb58db1b2 Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Thu, 13 Dec 2018 00:08:25 +0000 Subject: [PATCH] [Support] Fix FileNameLength passed to SetFileInformationByHandle The rename_internal function used for Windows has a minor bug where the filename length is passed as a character count instead of a byte count. Windows internally ignores this field, but other tools that hook NT api's may use the documented behavior: MSDN documentation specifying the size should be in bytes: https://docs.microsoft.com/en-us/windows/desktop/api/winbase/ns-winbase-_file_rename_info Patch by Ben Hillis. Differential Revision: https://reviews.llvm.org/D55624 llvm-svn: 348995 --- llvm/lib/Support/Windows/Path.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index 678c9a819d8b..d34aa763124c 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -416,7 +416,7 @@ static std::error_code rename_internal(HANDLE FromHandle, const Twine &To, *reinterpret_cast(RenameInfoBuf.data()); RenameInfo.ReplaceIfExists = ReplaceIfExists; RenameInfo.RootDirectory = 0; - RenameInfo.FileNameLength = ToWide.size(); + RenameInfo.FileNameLength = ToWide.size() * sizeof(wchar_t); std::copy(ToWide.begin(), ToWide.end(), &RenameInfo.FileName[0]); SetLastError(ERROR_SUCCESS);