2022-03-11 16:27:46 -08:00
|
|
|
From ef1c68c88caa4b4edfce72ad7fed38a4e23a56d1 Mon Sep 17 00:00:00 2001
|
2016-12-20 14:39:26 -08:00
|
|
|
From: Dmitry Timoshkov <dmitry@baikal.ru>
|
|
|
|
Date: Fri, 18 Nov 2016 22:31:29 +0800
|
2018-02-26 14:23:02 -08:00
|
|
|
Subject: [PATCH] uxtheme: Protect CloseThemeData() from invalid input.
|
2016-12-20 14:39:26 -08:00
|
|
|
MIME-Version: 1.0
|
|
|
|
Content-Type: text/plain; charset=UTF-8
|
|
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
|
|
|
|
Testcase by Michael Müller <michael@fds-team.de>.
|
|
|
|
---
|
2018-02-26 22:02:49 -08:00
|
|
|
dlls/uxtheme/msstyles.c | 22 ++++++++++++++++++++++
|
2016-12-20 14:39:26 -08:00
|
|
|
dlls/uxtheme/msstyles.h | 3 ++-
|
|
|
|
dlls/uxtheme/tests/system.c | 4 ++++
|
2018-02-26 22:02:49 -08:00
|
|
|
3 files changed, 28 insertions(+), 1 deletion(-)
|
2016-12-20 14:39:26 -08:00
|
|
|
|
|
|
|
diff --git a/dlls/uxtheme/msstyles.c b/dlls/uxtheme/msstyles.c
|
2022-03-11 16:27:46 -08:00
|
|
|
index 9e5a79a1c69..18c675214d9 100644
|
2016-12-20 14:39:26 -08:00
|
|
|
--- a/dlls/uxtheme/msstyles.c
|
|
|
|
+++ b/dlls/uxtheme/msstyles.c
|
2019-06-25 19:57:43 -07:00
|
|
|
@@ -32,6 +32,7 @@
|
|
|
|
|
2016-12-20 14:39:26 -08:00
|
|
|
#include "msstyles.h"
|
|
|
|
|
|
|
|
+#include "wine/exception.h"
|
|
|
|
#include "wine/debug.h"
|
2018-02-26 14:23:02 -08:00
|
|
|
#include "wine/heap.h"
|
2016-12-20 14:39:26 -08:00
|
|
|
|
2022-03-11 16:27:46 -08:00
|
|
|
@@ -49,6 +50,8 @@ static HRESULT MSSTYLES_GetFont (LPCWSTR lpStringStart, LPCWSTR lpStringEnd, LPC
|
2020-10-20 22:15:04 -07:00
|
|
|
|
|
|
|
#define MSSTYLES_VERSION 0x0003
|
2016-12-20 14:39:26 -08:00
|
|
|
|
|
|
|
+#define THEME_CLASS_SIGNATURE (('T' << 24) | ('H' << 16) | ('E' << 8) | 'M')
|
|
|
|
+
|
|
|
|
static PTHEME_FILE tfActiveTheme;
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2022-03-11 16:27:46 -08:00
|
|
|
@@ -204,6 +207,7 @@ void MSSTYLES_CloseThemeFile(PTHEME_FILE tf)
|
2018-02-26 22:02:49 -08:00
|
|
|
pcls->partstate = ps->next;
|
|
|
|
heap_free(ps);
|
|
|
|
}
|
|
|
|
+ pcls->signature = 0;
|
|
|
|
heap_free(pcls);
|
|
|
|
}
|
|
|
|
}
|
2022-03-11 16:27:46 -08:00
|
|
|
@@ -442,6 +446,7 @@ static PTHEME_CLASS MSSTYLES_AddClass(PTHEME_FILE tf, LPCWSTR pszAppName, LPCWST
|
2016-12-20 14:39:26 -08:00
|
|
|
if(cur) return cur;
|
|
|
|
|
2018-02-26 14:23:02 -08:00
|
|
|
cur = heap_alloc(sizeof(*cur));
|
2016-12-20 14:39:26 -08:00
|
|
|
+ cur->signature = THEME_CLASS_SIGNATURE;
|
|
|
|
cur->hTheme = tf->hTheme;
|
|
|
|
lstrcpyW(cur->szAppName, pszAppName);
|
|
|
|
lstrcpyW(cur->szClassName, pszClassName);
|
2022-03-11 16:27:46 -08:00
|
|
|
@@ -1075,6 +1080,23 @@ PTHEME_CLASS MSSTYLES_OpenThemeClass(LPCWSTR pszAppName, LPCWSTR pszClassList, U
|
2016-12-20 14:39:26 -08:00
|
|
|
*/
|
|
|
|
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
|
2022-03-11 16:27:46 -08:00
|
|
|
index 67f81315d7a..9a65b7cb8a7 100644
|
2016-12-20 14:39:26 -08:00
|
|
|
--- 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];
|
2022-03-11 16:27:46 -08:00
|
|
|
@@ -64,7 +65,7 @@ typedef struct _THEME_IMAGE {
|
2016-12-20 14:39:26 -08:00
|
|
|
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
|
2022-03-11 16:27:46 -08:00
|
|
|
index 93b6f1aa8f7..2e3a323f96c 100644
|
2016-12-20 14:39:26 -08:00
|
|
|
--- a/dlls/uxtheme/tests/system.c
|
|
|
|
+++ b/dlls/uxtheme/tests/system.c
|
2022-03-11 16:27:46 -08:00
|
|
|
@@ -528,6 +528,10 @@ static void test_OpenThemeData(void)
|
|
|
|
ok( GetLastError() == E_PROP_ID_UNSUPPORTED, "Expected 0x%08lx, got 0x%08lx\n",
|
2021-06-21 16:06:59 -07:00
|
|
|
E_PROP_ID_UNSUPPORTED, GetLastError() );
|
2016-12-20 14:39:26 -08:00
|
|
|
|
|
|
|
+ /* Close invalid handle */
|
|
|
|
+ hRes = CloseThemeData((HTHEME)0xdeadbeef);
|
2022-03-15 19:30:12 -07:00
|
|
|
+ ok( hRes == E_HANDLE, "Expected E_HANDLE, got 0x%08lx\n", hRes);
|
2016-12-20 14:39:26 -08:00
|
|
|
+
|
|
|
|
if (!bThemeActive)
|
|
|
|
{
|
|
|
|
SetLastError(0xdeadbeef);
|
|
|
|
--
|
2022-03-11 16:27:46 -08:00
|
|
|
2.35.1
|
2016-12-20 14:39:26 -08:00
|
|
|
|