[PATCH 1/2] ntdll: Don't write uninitialized bytes at the end of filenames
martin at martin.st
Thu May 15 07:25:04 CDT 2014
Some users of NtQueryDirectoryFile (notably, the compiler
in MSVC 2013) don't use the FileNameLength field, but memsets
the whole struct to 0 before calling NtQueryDirectoryFile, and
then counts the number of non-zero chars in FileName instead.
Previously we memcpied data from long_nameW to fill the whole
end of the struct, including the padding.
This fixes running cl.exe from MSVC 2013 (with native
msvcr120/msvcp120), fixing bug 35335.
MSVC 2013 seems to use NtQueryDirectoryFile to iterate through
files in directories before trying to open a file (both the
original source file and included headers). Prior to this change,
the file names found during iteration could get a suffix consisting
of an uninitialized WCHAR.
Additionally; on native Windows, the total number of bytes written
(signalled in io.Information) does not include the padding of the
last FILE_*_DIRECTORY_INFORMATION struct (which really indicates
that it doesn't write anything outside of the actual intended
data in the structs), while wine includes the padding here as
well, but this difference requires a larger patch to fix, and
the difference doesn't seem to matter in practice (for my case
dlls/ntdll/directory.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c
index 890fb71..50bf66a 100644
@@ -1484,7 +1484,7 @@ static union file_directory_info *append_entry( void *info_ptr, IO_STATUS_BLOCK
- memcpy( filename, long_nameW, total_len - ((char *)filename - (char *)info) );
+ memcpy( filename, long_nameW, long_len * sizeof(WCHAR) );
io->Information += total_len;
18.104.22.168 (Apple Git-48)
More information about the wine-patches