[PATCH v2 0/2] MR6900: oleaut32: Make OleCreateFontIndirect return error if font name is missing
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57457 -- v2: oleaut32: Remove a new unneeded null checks oleaut32: Make OleCreateFontIndirect return error if font name is missing https://gitlab.winehq.org/wine/wine/-/merge_requests/6900
From: Fabian Maurer <dark.shadow4(a)web.de> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57457 --- dlls/oleaut32/olefont.c | 2 ++ dlls/oleaut32/tests/olefont.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/dlls/oleaut32/olefont.c b/dlls/oleaut32/olefont.c index aea8b596498..bbb732f10de 100644 --- a/dlls/oleaut32/olefont.c +++ b/dlls/oleaut32/olefont.c @@ -337,6 +337,8 @@ HRESULT WINAPI OleCreateFontIndirect( fd.fStrikethrough = FALSE; lpFontDesc = &fd; } + else if (!lpFontDesc->lpstrName) + return CTL_E_INVALIDPROPERTYVALUE; newFont = OLEFontImpl_Construct(lpFontDesc); if (!newFont) return E_OUTOFMEMORY; diff --git a/dlls/oleaut32/tests/olefont.c b/dlls/oleaut32/tests/olefont.c index a8736cd0172..85b5ac99fad 100644 --- a/dlls/oleaut32/tests/olefont.c +++ b/dlls/oleaut32/tests/olefont.c @@ -1224,6 +1224,7 @@ static void test_OleCreateFontIndirect(void) IUnknown *unk, *unk2; IFont *font; HRESULT hr; + WCHAR str_empty[] = {0}; fontdesc.cbSizeofstruct = sizeof(fontdesc); fontdesc.lpstrName = arial_font; @@ -1254,6 +1255,22 @@ static void test_OleCreateFontIndirect(void) EXPECT_HR(hr, S_OK); IFont_Release(font); + /* Test NULL name */ + fontdesc.cbSizeofstruct = sizeof(fontdesc); + fontdesc.lpstrName = NULL; + font = (IFont*)0xdeadbeef; + hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font); + EXPECT_HR(hr, CTL_E_INVALIDPROPERTYVALUE); + ok(font == 0, "Got %p\n", font); + + /* Test empty Name */ + fontdesc.lpstrName = str_empty; + font = NULL; + hr = pOleCreateFontIndirect(&fontdesc, &IID_IFont, (void**)&font); + EXPECT_HR(hr, S_OK); + ok(font != 0, "Got NULL font\n"); + IFont_Release(font); + hr = OleInitialize(NULL); ok(hr == S_OK, "got 0x%08lx\n", hr); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/6900
From: Fabian Maurer <dark.shadow4(a)web.de> Now that we check for null in the constructor, the name can't be null anymore --- dlls/oleaut32/olefont.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/dlls/oleaut32/olefont.c b/dlls/oleaut32/olefont.c index bbb732f10de..f1af3f4cb70 100644 --- a/dlls/oleaut32/olefont.c +++ b/dlls/oleaut32/olefont.c @@ -636,10 +636,7 @@ static HRESULT WINAPI OLEFontImpl_get_Name( realize_font(this); - if (this->description.lpstrName!=0) - *pname = SysAllocString(this->description.lpstrName); - else - *pname = 0; + *pname = SysAllocString(this->description.lpstrName); return S_OK; } @@ -1672,11 +1669,8 @@ static HRESULT WINAPI OLEFontImpl_Save( if (written != sizeof(DWORD)) return E_FAIL; /* FontName */ - if (this->description.lpstrName) - string_size = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName, - lstrlenW(this->description.lpstrName), NULL, 0, NULL, NULL ); - else - string_size = 0; + string_size = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName, + lstrlenW(this->description.lpstrName), NULL, 0, NULL, NULL ); IStream_Write(pOutStream, &string_size, sizeof(BYTE), &written); if (written != sizeof(BYTE)) return E_FAIL; @@ -1719,10 +1713,9 @@ static HRESULT WINAPI OLEFontImpl_GetSizeMax( pcbSize->u.LowPart += sizeof(DWORD); /* Size */ pcbSize->u.LowPart += sizeof(BYTE); /* StrLength */ - if (this->description.lpstrName!=0) - pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName, - lstrlenW(this->description.lpstrName), - NULL, 0, NULL, NULL ); + pcbSize->u.LowPart += WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName, + lstrlenW(this->description.lpstrName), + NULL, 0, NULL, NULL ); return S_OK; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/6900
On Tue Nov 26 19:34:18 2024 +0000, Fabian Maurer wrote:
changed this line in [version 2 of the diff](/wine/wine/-/merge_requests/6900/diffs?diff_id=145570&start_sha=7620338f2c23147c1d6f635a15cdf89e8bddfb2c#d8c289884ebe99f3b4324f8263c13f9527dac8f6_1268_1268) Updated
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/6900#note_88953
On Tue Nov 26 08:15:58 2024 +0000, Nikolay Sivov wrote:
I'd put that as "else" branch of the existing "if". Thanks, updated
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/6900#note_88954
participants (2)
-
Fabian Maurer -
Fabian Maurer (@DarkShadow44)