sync kernel32/misc/profile.c to wine

kernel32: Fix uninitialised memory read in GetPrivateProfileStringA 	if GetPrivateProfileStringW returns 0.  <robertshearman at gmail dot com>

svn path=/trunk/; revision=44417
This commit is contained in:
Christoph von Wittich 2009-12-05 19:35:03 +00:00
parent 77cae0674b
commit 1e17486780

View file

@ -333,8 +333,7 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
return NULL; return NULL;
buffer_base = HeapAlloc(GetProcessHeap(), 0 , dwFileSize); buffer_base = HeapAlloc(GetProcessHeap(), 0 , dwFileSize);
if (!buffer_base) if (!buffer_base) return NULL;
return NULL;
if (!ReadFile(hFile, buffer_base, dwFileSize, &dwFileSize, NULL)) if (!ReadFile(hFile, buffer_base, dwFileSize, &dwFileSize, NULL))
{ {
@ -363,7 +362,6 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, szFile, len); MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, szFile, len);
szEnd = szFile + len; szEnd = szFile + len;
break; break;
case ENCODING_UTF8: case ENCODING_UTF8:
DPRINT("UTF8 encoding\n"); DPRINT("UTF8 encoding\n");
@ -377,20 +375,17 @@ static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding)
MultiByteToWideChar(CP_UTF8, 0, pBuffer, dwFileSize, szFile, len); MultiByteToWideChar(CP_UTF8, 0, pBuffer, dwFileSize, szFile, len);
szEnd = szFile + len; szEnd = szFile + len;
break; break;
case ENCODING_UTF16LE: case ENCODING_UTF16LE:
DPRINT("UTF16 Little Endian encoding\n"); DPRINT("UTF16 Little Endian encoding\n");
szFile = pBuffer; szFile = pBuffer;
szEnd = (WCHAR *)((char *)pBuffer + dwFileSize); szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
break; break;
case ENCODING_UTF16BE: case ENCODING_UTF16BE:
DPRINT("UTF16 Big Endian encoding\n"); DPRINT("UTF16 Big Endian encoding\n");
szFile = pBuffer; szFile = pBuffer;
szEnd = (WCHAR *)((char *)pBuffer + dwFileSize); szEnd = (WCHAR *)((char *)pBuffer + dwFileSize);
PROFILE_ByteSwapShortBuffer(szFile, dwFileSize / sizeof(WCHAR)); PROFILE_ByteSwapShortBuffer(szFile, dwFileSize / sizeof(WCHAR));
break; break;
default: default:
DPRINT("encoding type %d not implemented\n", *pEncoding); DPRINT("encoding type %d not implemented\n", *pEncoding);
HeapFree(GetProcessHeap(), 0, buffer_base); HeapFree(GetProcessHeap(), 0, buffer_base);
@ -849,9 +844,7 @@ static BOOL PROFILE_Open( LPCWSTR filename, BOOL write_access )
MRUProfile[i] = MRUProfile[i-1]; MRUProfile[i] = MRUProfile[i-1];
CurProfile=tempProfile; 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 */ /* OK, now that CurProfile is definitely free we assign it our new file */
CurProfile->filename = HeapAlloc( GetProcessHeap(), 0, (wcslen(buffer)+1) * sizeof(WCHAR) ); CurProfile->filename = HeapAlloc( GetProcessHeap(), 0, (wcslen(buffer)+1) * sizeof(WCHAR) );
@ -1209,14 +1202,13 @@ DWORD WINAPI GetPrivateProfileStringA( LPCSTR section, LPCSTR entry,
filenameW.Buffer); filenameW.Buffer);
if (len) if (len)
{ {
ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW + 1, buffer, len, NULL, NULL); if (retW)
if (!ret)
{ {
ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW, buffer, len - 1, NULL, NULL);
if (!ret)
ret = len - 1; ret = len - 1;
buffer[ret] = 0;
} }
else buffer[ret] = 0;
ret--; /* strip terminating 0 */
} }
RtlFreeUnicodeString(&sectionW); RtlFreeUnicodeString(&sectionW);