[llvm] r348995 - [Support] Fix FileNameLength passed to SetFileInformationByHandle

Shoaib Meenai via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 12 16:08:25 PST 2018


Author: smeenai
Date: Wed Dec 12 16:08:25 2018
New Revision: 348995

URL: http://llvm.org/viewvc/llvm-project?rev=348995&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Support/Windows/Path.inc

Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=348995&r1=348994&r2=348995&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Wed Dec 12 16:08:25 2018
@@ -416,7 +416,7 @@ static std::error_code rename_internal(H
       *reinterpret_cast<FILE_RENAME_INFO *>(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);




More information about the llvm-commits mailing list