Author: pschweitzer
Date: Sun Feb 20 22:57:31 2011
New Revision: 50849
URL:
http://svn.reactos.org/svn/reactos?rev=50849&view=rev
Log:
[KERNEL32]
Don't mix tab index and memory length...
This fixes several bugs in GetTempFileNameW() and prevents memory corruption ~
Winetest regression is gone :)
Modified:
trunk/reactos/dll/win32/kernel32/file/file.c
Modified: trunk/reactos/dll/win32/kernel32/file/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/file/fi…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/file/file.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/file/file.c [iso-8859-1] Sun Feb 20 22:57:31 2011
@@ -1287,7 +1287,7 @@
static const WCHAR Ext[] = { L'.', 't', 'm', 'p',
UNICODE_NULL };
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);
}
@@ -1306,15 +1306,15 @@
{
memmove(lpTempFileName, PathNameString.Buffer, PathNameString.Length);
}
-
+
/* 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);
if (FileAttributes == INVALID_FILE_ATTRIBUTES)
{
/* Append a '\' if necessary */
- lpTempFileName[PathNameString.Length - sizeof(WCHAR)] = L'\\';
- lpTempFileName[PathNameString.Length] = UNICODE_NULL;
+ lpTempFileName[(PathNameString.Length / sizeof(WCHAR)) - 1] = L'\\';
+ lpTempFileName[PathNameString.Length / sizeof(WCHAR)] = UNICODE_NULL;
FileAttributes = GetFileAttributesW(lpTempFileName);
if (FileAttributes == INVALID_FILE_ATTRIBUTES)
{
@@ -1329,7 +1329,7 @@
}
/* Make sure not to mix path & prefix */
- lpTempFileName[PathNameString.Length - sizeof(WCHAR)] = L'\\';
+ lpTempFileName[(PathNameString.Length / sizeof(WCHAR)) - 1] = L'\\';
RtlInitUnicodeString(&PrefixString, lpPrefixString);
if (PrefixString.Length > 3 * sizeof(WCHAR))
{
@@ -1337,7 +1337,7 @@
}
/* Append prefix to path */
- TempFileName = lpTempFileName + PathNameString.Length / sizeof(WCHAR) - 1;
+ TempFileName = lpTempFileName + PathNameString.Length / sizeof(WCHAR);
memmove(TempFileName, PrefixString.Buffer, PrefixString.Length);
TempFileName += PrefixString.Length / sizeof(WCHAR);
@@ -1364,8 +1364,8 @@
/* Convert that ID to wchar */
RtlIntegerToChar(ID, 0x10, sizeof(IDString), IDString);
Let = IDString;
- do
- {
+ do
+ {
*(TempFileName++) = RtlAnsiCharToUnicodeChar(&Let);
} while (*Let != 0);