mirror of
https://github.com/reactos/reactos.git
synced 2024-09-06 10:52:52 +00:00
[KERNEL32]
Don't mix tab index and memory length... This fixes several bugs in GetTempFileNameW() and prevents memory corruption ~ Winetest regression is gone :) svn path=/trunk/; revision=50849
This commit is contained in:
parent
98eeb0943d
commit
397fb380b3
|
@ -1287,7 +1287,7 @@ GetTempFileNameW(IN LPCWSTR lpPathName,
|
||||||
static const WCHAR Ext[] = { L'.', 't', 'm', 'p', UNICODE_NULL };
|
static const WCHAR Ext[] = { L'.', 't', 'm', 'p', UNICODE_NULL };
|
||||||
|
|
||||||
RtlInitUnicodeString(&PathNameString, lpPathName);
|
RtlInitUnicodeString(&PathNameString, lpPathName);
|
||||||
if (PathNameString.Length == 0 || PathNameString.Buffer[PathNameString.Length - sizeof(WCHAR)] != L'\\')
|
if (PathNameString.Length == 0 || PathNameString.Buffer[(PathNameString.Length / sizeof(WCHAR)) - 1] != L'\\')
|
||||||
{
|
{
|
||||||
PathNameString.Length += sizeof(WCHAR);
|
PathNameString.Length += sizeof(WCHAR);
|
||||||
}
|
}
|
||||||
|
@ -1308,13 +1308,13 @@ GetTempFileNameW(IN LPCWSTR lpPathName,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PathName MUST BE a path. Check it */
|
/* PathName MUST BE a path. Check it */
|
||||||
lpTempFileName[PathNameString.Length - sizeof(WCHAR)] = UNICODE_NULL;
|
lpTempFileName[(PathNameString.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL;
|
||||||
FileAttributes = GetFileAttributesW(lpTempFileName);
|
FileAttributes = GetFileAttributesW(lpTempFileName);
|
||||||
if (FileAttributes == INVALID_FILE_ATTRIBUTES)
|
if (FileAttributes == INVALID_FILE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
/* Append a '\' if necessary */
|
/* Append a '\' if necessary */
|
||||||
lpTempFileName[PathNameString.Length - sizeof(WCHAR)] = L'\\';
|
lpTempFileName[(PathNameString.Length / sizeof(WCHAR)) - 1] = L'\\';
|
||||||
lpTempFileName[PathNameString.Length] = UNICODE_NULL;
|
lpTempFileName[PathNameString.Length / sizeof(WCHAR)] = UNICODE_NULL;
|
||||||
FileAttributes = GetFileAttributesW(lpTempFileName);
|
FileAttributes = GetFileAttributesW(lpTempFileName);
|
||||||
if (FileAttributes == INVALID_FILE_ATTRIBUTES)
|
if (FileAttributes == INVALID_FILE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
|
@ -1329,7 +1329,7 @@ GetTempFileNameW(IN LPCWSTR lpPathName,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure not to mix path & prefix */
|
/* Make sure not to mix path & prefix */
|
||||||
lpTempFileName[PathNameString.Length - sizeof(WCHAR)] = L'\\';
|
lpTempFileName[(PathNameString.Length / sizeof(WCHAR)) - 1] = L'\\';
|
||||||
RtlInitUnicodeString(&PrefixString, lpPrefixString);
|
RtlInitUnicodeString(&PrefixString, lpPrefixString);
|
||||||
if (PrefixString.Length > 3 * sizeof(WCHAR))
|
if (PrefixString.Length > 3 * sizeof(WCHAR))
|
||||||
{
|
{
|
||||||
|
@ -1337,7 +1337,7 @@ GetTempFileNameW(IN LPCWSTR lpPathName,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append prefix to path */
|
/* Append prefix to path */
|
||||||
TempFileName = lpTempFileName + PathNameString.Length / sizeof(WCHAR) - 1;
|
TempFileName = lpTempFileName + PathNameString.Length / sizeof(WCHAR);
|
||||||
memmove(TempFileName, PrefixString.Buffer, PrefixString.Length);
|
memmove(TempFileName, PrefixString.Buffer, PrefixString.Length);
|
||||||
TempFileName += PrefixString.Length / sizeof(WCHAR);
|
TempFileName += PrefixString.Length / sizeof(WCHAR);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue