kernel32: Fix uninitialised memory read in GetPrivateProfileStringA if GetPrivateProfileStringW returns 0.

The buffer that was passed into the function will remain
uninitialised. Fix reading from this by only reading retW characters
from bufferW and manually nul-terminating the string.
This commit is contained in:
Rob Shearman 2009-11-29 10:34:19 +00:00 committed by Alexandre Julliard
parent 2226b678e3
commit 47acaeaea8
1 changed files with 5 additions and 6 deletions

View File

@ -1173,14 +1173,13 @@ INT WINAPI GetPrivateProfileStringA( LPCSTR section, LPCSTR entry,
filenameW.Buffer);
if (len)
{
ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW + 1, buffer, len, NULL, NULL);
if (!ret)
if (retW)
{
ret = len - 1;
buffer[ret] = 0;
ret = WideCharToMultiByte(CP_ACP, 0, bufferW, retW, buffer, len - 1, NULL, NULL);
if (!ret)
ret = len - 1;
}
else
ret--; /* strip terminating 0 */
buffer[ret] = 0;
}
RtlFreeUnicodeString(&sectionW);