Author: cwittich
Date: Sat Dec 5 20:35:03 2009
New Revision: 44417
URL:
http://svn.reactos.org/svn/reactos?rev=44417&view=rev
Log:
sync kernel32/misc/profile.c to wine
kernel32: Fix uninitialised memory read in GetPrivateProfileStringA if
GetPrivateProfileStringW returns 0. <robertshearman at gmail dot com>
Modified:
trunk/reactos/dll/win32/kernel32/misc/profile.c
Modified: trunk/reactos/dll/win32/kernel32/misc/profile.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/misc/pr…
==============================================================================
--- trunk/reactos/dll/win32/kernel32/misc/profile.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/misc/profile.c [iso-8859-1] Sat Dec 5 20:35:03 2009
@@ -333,9 +333,8 @@
return NULL;
buffer_base = HeapAlloc(GetProcessHeap(), 0 , dwFileSize);
- if (!buffer_base)
- return NULL;
-
+ if (!buffer_base) return NULL;
+
if (!ReadFile(hFile, buffer_base, dwFileSize, &dwFileSize, NULL))
{
HeapFree(GetProcessHeap(), 0, buffer_base);
@@ -363,7 +362,6 @@
MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, szFile, len);
szEnd = szFile + len;
break;
-
case ENCODING_UTF8:
DPRINT("UTF8 encoding\n");
@@ -377,20 +375,17 @@
MultiByteToWideChar(CP_UTF8, 0, pBuffer, dwFileSize, szFile, len);
szEnd = szFile + len;
break;
-
case ENCODING_UTF16LE:
DPRINT("UTF16 Little Endian encoding\n");
szFile = pBuffer;
szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
break;
-
case ENCODING_UTF16BE:
DPRINT("UTF16 Big Endian encoding\n");
szFile = pBuffer;
szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
PROFILE_ByteSwapShortBuffer(szFile, dwFileSize / sizeof(WCHAR));
break;
-
default:
DPRINT("encoding type %d not implemented\n", *pEncoding);
HeapFree(GetProcessHeap(), 0, buffer_base);
@@ -398,7 +393,7 @@
}
first_section = HeapAlloc( GetProcessHeap(), 0, sizeof(*section) );
- if (first_section == NULL)
+ if(first_section == NULL)
{
if (szFile != pBuffer)
HeapFree(GetProcessHeap(), 0, szFile);
@@ -849,9 +844,7 @@
MRUProfile[i] = MRUProfile[i-1];
CurProfile=tempProfile;
}
-
- if (CurProfile->filename)
- PROFILE_ReleaseFile();
+ if(CurProfile->filename) PROFILE_ReleaseFile();
/* OK, now that CurProfile is definitely free we assign it our new file */
CurProfile->filename = HeapAlloc( GetProcessHeap(), 0, (wcslen(buffer)+1) *
sizeof(WCHAR) );
@@ -1209,14 +1202,13 @@
filenameW.Buffer);
if (len)
{
- ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW + 1, buffer, len, NULL,
NULL);
- if (!ret)
- {
- ret = len - 1;
- buffer[ret] = 0;
- }
- else
- ret--; /* strip terminating 0 */
+ if (retW)
+ {
+ ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW, buffer, len - 1, NULL,
NULL);
+ if (!ret)
+ ret = len - 1;
+ }
+ buffer[ret] = 0;
}
RtlFreeUnicodeString(§ionW);