[WIN32SS][FONT] Define IntUnicodeStringToBuffer function and use it (#1004)

- Define IntUnicodeStringToBuffer function to copy the contents of a UNICODE_STRING to a string buffer with a UNICODE_NULL correctly.
- Use it.
JIRA issue: N/A
This commit is contained in:
Katayama Hirofumi MZ 2018-11-03 05:42:58 +09:00 committed by GitHub
parent 4abba2b7ac
commit 2737d9144d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -741,6 +741,21 @@ SubstituteFontByList(PLIST_ENTRY pHead,
return FALSE; return FALSE;
} }
static VOID
IntUnicodeStringToBuffer(LPWSTR pszBuffer, USHORT cbBuffer, const UNICODE_STRING *pString)
{
USHORT cbLength = pString->Length;
if (cbBuffer < sizeof(UNICODE_NULL))
return;
if (cbLength > cbBuffer - sizeof(UNICODE_NULL))
cbLength = cbBuffer - sizeof(UNICODE_NULL);
RtlCopyMemory(pszBuffer, pString->Buffer, cbLength);
pszBuffer[cbLength / sizeof(WCHAR)] = UNICODE_NULL;
}
static BOOL static BOOL
SubstituteFontRecurse(LOGFONTW* pLogFont) SubstituteFontRecurse(LOGFONTW* pLogFont)
{ {
@ -763,7 +778,7 @@ SubstituteFontRecurse(LOGFONTW* pLogFont)
if (!Found) if (!Found)
break; break;
RtlStringCchCopyW(pLogFont->lfFaceName, LF_FACESIZE, OutputNameW.Buffer); IntUnicodeStringToBuffer(pLogFont->lfFaceName, sizeof(pLogFont->lfFaceName), &OutputNameW);
if (CharSetMap[FONTSUBST_FROM] == DEFAULT_CHARSET || if (CharSetMap[FONTSUBST_FROM] == DEFAULT_CHARSET ||
CharSetMap[FONTSUBST_FROM] == pLogFont->lfCharSet) CharSetMap[FONTSUBST_FROM] == pLogFont->lfCharSet)
@ -1037,8 +1052,8 @@ IntGdiLoadFontsFromMemory(PGDI_LOAD_FONT pLoadFont,
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY); EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0; /* failure */ return 0; /* failure */
} }
RtlCopyMemory(FontGDI->Filename, pFileName->Buffer, pFileName->Length);
FontGDI->Filename[pFileName->Length / sizeof(WCHAR)] = UNICODE_NULL; IntUnicodeStringToBuffer(FontGDI->Filename, sizeof(FontGDI->Filename), pFileName);
} }
else else
{ {
@ -2588,7 +2603,7 @@ FontFamilyFillInfo(PFONTFAMILYINFO Info, LPCWSTR FaceName,
/* full name */ /* full name */
if (!FullName) if (!FullName)
FullName = (WCHAR*)((ULONG_PTR) Otm + (ULONG_PTR)Otm->otmpFaceName); FullName = (WCHAR*)((ULONG_PTR) Otm + (ULONG_PTR)Otm->otmpFaceName);
RtlStringCbCopyW(Info->EnumLogFontEx.elfFullName, RtlStringCbCopyW(Info->EnumLogFontEx.elfFullName,
sizeof(Info->EnumLogFontEx.elfFullName), sizeof(Info->EnumLogFontEx.elfFullName),
FullName); FullName);
@ -2815,7 +2830,7 @@ GetFontFamilyInfoForSubstitutes(LPLOGFONTW LogFont,
continue; /* mismatch */ continue; /* mismatch */
} }
RtlStringCchCopyW(lf.lfFaceName, LF_FACESIZE, pFromW->Buffer); IntUnicodeStringToBuffer(lf.lfFaceName, sizeof(lf.lfFaceName), pFromW);
SubstituteFontRecurse(&lf); SubstituteFontRecurse(&lf);
RtlInitUnicodeString(&NameW, lf.lfFaceName); RtlInitUnicodeString(&NameW, lf.lfFaceName);
@ -4986,9 +5001,7 @@ TextIntRealizeFont(HFONT FontHandle, PTEXTOBJ pTextObj)
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* truncated copy */ /* truncated copy */
Name.Length = (USHORT)min(Name.Length, (LF_FACESIZE - 1) * sizeof(WCHAR)); IntUnicodeStringToBuffer(TextObj->TextFace, sizeof(TextObj->TextFace), &Name);
RtlStringCbCopyNW(TextObj->TextFace, Name.Length + sizeof(WCHAR), Name.Buffer, Name.Length);
RtlFreeUnicodeString(&Name); RtlFreeUnicodeString(&Name);
} }
} }