From 8c7a7c6ba3e1a7752bd0bb5d58e01cc7c3475c88 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Fri, 18 Nov 2016 22:31:29 +0800 Subject: [PATCH] uxtheme: Protect CloseThemeData() from invalid input. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Testcase by Michael Müller . --- dlls/uxtheme/msstyles.c | 22 ++++++++++++++++++++++ dlls/uxtheme/msstyles.h | 3 ++- dlls/uxtheme/tests/system.c | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/dlls/uxtheme/msstyles.c b/dlls/uxtheme/msstyles.c index ed22d923250..21106a5f8e0 100644 --- a/dlls/uxtheme/msstyles.c +++ b/dlls/uxtheme/msstyles.c @@ -32,6 +32,7 @@ #include "msstyles.h" +#include "wine/exception.h" #include "wine/debug.h" #include "wine/heap.h" @@ -48,6 +49,8 @@ static HRESULT MSSTYLES_GetFont (LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPC #define MSSTYLES_VERSION 0x0003 +#define THEME_CLASS_SIGNATURE (('T' << 24) | ('H' << 16) | ('E' << 8) | 'M') + static PTHEME_FILE tfActiveTheme; /***********************************************************************/ @@ -203,6 +206,7 @@ void MSSTYLES_CloseThemeFile(PTHEME_FILE tf) pcls->partstate = ps->next; heap_free(ps); } + pcls->signature = 0; heap_free(pcls); } } @@ -431,6 +435,7 @@ static PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWST if(cur) return cur; cur = heap_alloc(sizeof(*cur)); + cur->signature = THEME_CLASS_SIGNATURE; cur->hTheme = tf->hTheme; lstrcpyW(cur->szAppName, pszAppName); lstrcpyW(cur->szClassName, pszClassName); @@ -1022,6 +1027,23 @@ PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList) */ HRESULT MSSTYLES_CloseThemeClass(PTHEME_CLASS tc) { + __TRY + { + if (tc->signature != THEME_CLASS_SIGNATURE) + tc = NULL; + } + __EXCEPT_PAGE_FAULT + { + tc = NULL; + } + __ENDTRY + + if (!tc) + { + WARN("Invalid theme class handle\n"); + return E_HANDLE; + } + MSSTYLES_CloseThemeFile (tc->tf); return S_OK; } diff --git a/dlls/uxtheme/msstyles.h b/dlls/uxtheme/msstyles.h index 0b7e1ab35cc..ba10ac82b82 100644 --- a/dlls/uxtheme/msstyles.h +++ b/dlls/uxtheme/msstyles.h @@ -49,6 +49,7 @@ typedef struct _THEME_PARTSTATE { struct _THEME_FILE; typedef struct _THEME_CLASS { + DWORD signature; HMODULE hTheme; struct _THEME_FILE* tf; WCHAR szAppName[MAX_THEME_APP_NAME]; @@ -63,7 +64,7 @@ typedef struct _THEME_IMAGE { WCHAR name[MAX_PATH]; HBITMAP image; BOOL hasAlpha; - + struct _THEME_IMAGE *next; } THEME_IMAGE, *PTHEME_IMAGE; diff --git a/dlls/uxtheme/tests/system.c b/dlls/uxtheme/tests/system.c index 869dbe2cdc9..f5097012a2d 100644 --- a/dlls/uxtheme/tests/system.c +++ b/dlls/uxtheme/tests/system.c @@ -195,6 +195,10 @@ static void test_OpenThemeData(void) ok( GetLastError() == E_PROP_ID_UNSUPPORTED, "Expected 0x%08x, got 0x%08x\n", E_PROP_ID_UNSUPPORTED, GetLastError() ); + /* Close invalid handle */ + hRes = CloseThemeData((HTHEME)0xdeadbeef); + ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08x\n", hRes); + if (!bThemeActive) { SetLastError(0xdeadbeef); -- 2.30.2