https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2158f31b7128fea95f0ab…
commit 2158f31b7128fea95f0ab5e40067dd93e70b8dca
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Jul 22 21:32:38 2018 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Jul 22 21:32:38 2018 +0200
[KERNEL32] Use RtlStringCbCopyNW() to correctly fill the WIN32_FIND_DATA.cFileName and
cAlternateFileName members without any overflow and with a terminating NULL character.
---
dll/win32/kernel32/client/file/disk.c | 1 -
dll/win32/kernel32/client/file/find.c | 39 +++++++++++++++++++----------------
2 files changed, 21 insertions(+), 19 deletions(-)
diff --git a/dll/win32/kernel32/client/file/disk.c
b/dll/win32/kernel32/client/file/disk.c
index 6d13e64acb..7fe8061666 100644
--- a/dll/win32/kernel32/client/file/disk.c
+++ b/dll/win32/kernel32/client/file/disk.c
@@ -19,7 +19,6 @@
*/
#include <k32.h>
-#include <strsafe.h>
#define NDEBUG
#include <debug.h>
diff --git a/dll/win32/kernel32/client/file/find.c
b/dll/win32/kernel32/client/file/find.c
index 4a2d1520e6..b5fe7713e5 100644
--- a/dll/win32/kernel32/client/file/find.c
+++ b/dll/win32/kernel32/client/file/find.c
@@ -5,12 +5,14 @@
* PURPOSE: Find functions
* PROGRAMMERS: Ariadne (ariadne(a)xs4all.nl)
* Pierre Schweitzer (pierre.schweitzer(a)reactos.org)
- * Hermes BELUSCA - MAITO (hermes.belusca(a)sfr.fr)
+ * Hermes Belusca-Maito
*/
/* INCLUDES *******************************************************************/
#include <k32.h>
+#include <ntstrsafe.h>
+
#define NDEBUG
#include <debug.h>
DEBUG_CHANNEL(kernel32file);
@@ -71,7 +73,7 @@ typedef struct _FIND_FILE_DATA
/*
* For handling STATUS_BUFFER_OVERFLOW errors emitted by
- * NtQueryDirectoryFile in the FildNextFile function.
+ * NtQueryDirectoryFile in the FindNextFile function.
*/
BOOLEAN HasMoreData;
@@ -128,9 +130,9 @@ CopyDeviceFindData(OUT LPWIN32_FIND_DATAW lpFindFileData,
/* Return the data */
RtlZeroMemory(lpFindFileData, sizeof(*lpFindFileData));
lpFindFileData->dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE;
- RtlCopyMemory(lpFindFileData->cFileName,
- DeviceName,
- Length);
+ RtlStringCbCopyNW(lpFindFileData->cFileName,
+ sizeof(lpFindFileData->cFileName),
+ DeviceName, Length);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
@@ -175,22 +177,22 @@ do { \
if (fInfoLevelId == FindExInfoStandard)
{
- RtlCopyMemory(lpFindFileData->cFileName,
- DirInfo.BothDirInfo->FileName,
- DirInfo.BothDirInfo->FileNameLength);
- lpFindFileData->cFileName[DirInfo.BothDirInfo->FileNameLength /
sizeof(WCHAR)] = UNICODE_NULL;
-
- RtlCopyMemory(lpFindFileData->cAlternateFileName,
- DirInfo.BothDirInfo->ShortName,
- DirInfo.BothDirInfo->ShortNameLength);
- lpFindFileData->cAlternateFileName[DirInfo.BothDirInfo->ShortNameLength
/ sizeof(WCHAR)] = UNICODE_NULL;
+ RtlStringCbCopyNW(lpFindFileData->cFileName,
+ sizeof(lpFindFileData->cFileName),
+ DirInfo.BothDirInfo->FileName,
+ DirInfo.BothDirInfo->FileNameLength);
+
+ RtlStringCbCopyNW(lpFindFileData->cAlternateFileName,
+ sizeof(lpFindFileData->cAlternateFileName),
+ DirInfo.BothDirInfo->ShortName,
+ DirInfo.BothDirInfo->ShortNameLength);
}
else if (fInfoLevelId == FindExInfoBasic)
{
- RtlCopyMemory(lpFindFileData->cFileName,
- DirInfo.FullDirInfo->FileName,
- DirInfo.FullDirInfo->FileNameLength);
- lpFindFileData->cFileName[DirInfo.FullDirInfo->FileNameLength /
sizeof(WCHAR)] = UNICODE_NULL;
+ RtlStringCbCopyNW(lpFindFileData->cFileName,
+ sizeof(lpFindFileData->cFileName),
+ DirInfo.FullDirInfo->FileName,
+ DirInfo.FullDirInfo->FileNameLength);
lpFindFileData->cAlternateFileName[0] = UNICODE_NULL;
}
@@ -554,6 +556,7 @@ FindClose(HANDLE hFindFile)
_SEH2_YIELD(return FALSE);
}
_SEH2_END;
+
return TRUE;
}