Dmitry Timoshkov : comctl32: Check control type in the STM_SETIMAGE/STM_SETICON handlers before calling the helpers.
Alexandre Julliard
julliard at winehq.org
Wed Aug 18 16:22:11 CDT 2021
Module: wine
Branch: master
Commit: 9b7faf98a9853cece4ecc2021943b97706f0dd01
URL: https://source.winehq.org/git/wine.git/?a=commit;h=9b7faf98a9853cece4ecc2021943b97706f0dd01
Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date: Wed Aug 18 12:36:30 2021 +0300
comctl32: Check control type in the STM_SETIMAGE/STM_SETICON handlers before calling the helpers.
Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/comctl32/static.c | 7 +--
dlls/comctl32/tests/static.c | 121 +++++++++++++++++++++++++++++++++++++++++--
2 files changed, 122 insertions(+), 6 deletions(-)
diff --git a/dlls/comctl32/static.c b/dlls/comctl32/static.c
index 2bd2b22bc20..60af6696425 100644
--- a/dlls/comctl32/static.c
+++ b/dlls/comctl32/static.c
@@ -133,7 +133,6 @@ static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
SIZE size;
struct static_extra_info *extra;
- if ((style & SS_TYPEMASK) != SS_ICON) return 0;
if (hicon && !get_icon_size( hicon, &size ))
{
WARN("hicon != 0, but invalid\n");
@@ -220,7 +219,6 @@ static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
HBITMAP hOldBitmap, alpha;
struct static_extra_info *extra;
- if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP)
{
WARN("hBitmap != 0, but it's not a bitmap\n");
@@ -277,7 +275,6 @@ static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile,
HENHMETAFILE old_hemf;
struct static_extra_info *extra;
- if ((style & SS_TYPEMASK) != SS_ENHMETAFILE) return 0;
if (hEnhMetaFile && GetObjectType(hEnhMetaFile) != OBJ_ENHMETAFILE)
{
WARN("hEnhMetaFile != 0, but it's not an enhanced metafile\n");
@@ -594,13 +591,16 @@ static LRESULT CALLBACK STATIC_WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam,
switch (wParam)
{
case IMAGE_BITMAP:
+ if (style != SS_BITMAP) return 0;
lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
break;
case IMAGE_ENHMETAFILE:
+ if (style != SS_ENHMETAFILE) return 0;
lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
break;
case IMAGE_ICON:
case IMAGE_CURSOR:
+ if (style != SS_ICON) return 0;
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
break;
default:
@@ -611,6 +611,7 @@ static LRESULT CALLBACK STATIC_WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam,
break;
case STM_SETICON:
+ if (style != SS_ICON) return 0;
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
STATIC_TryPaintFcn( hwnd, full_style );
break;
diff --git a/dlls/comctl32/tests/static.c b/dlls/comctl32/tests/static.c
index 4efb7685790..40a337b97b0 100644
--- a/dlls/comctl32/tests/static.c
+++ b/dlls/comctl32/tests/static.c
@@ -20,9 +20,11 @@
#include <stdarg.h>
#include <stdio.h>
-#define STRICT
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
+#include "windef.h"
+#include "winbase.h"
+#include "wingdi.h"
+#define OEMRESOURCE
+#include "winuser.h"
#include "commctrl.h"
#include "resources.h"
@@ -263,6 +265,118 @@ static void test_set_image(void)
DeleteObject(image);
}
+static void test_STM_SETIMAGE(void)
+{
+ DWORD type;
+ HWND hwnd;
+ HICON icon, old_image;
+ HBITMAP bmp;
+ HENHMETAFILE emf;
+ HDC dc;
+
+ icon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
+ bmp = LoadBitmapW(0, (LPCWSTR)OBM_CLOSE);
+ dc = CreateEnhMetaFileW(0, NULL, NULL, NULL);
+ LineTo(dc, 1, 1);
+ emf = CloseEnhMetaFile(dc);
+ DeleteDC(dc);
+
+ for (type = SS_LEFT; type < SS_ETCHEDFRAME; type++)
+ {
+ winetest_push_context("%u", type);
+
+ hwnd = create_static(type);
+ ok(hwnd != 0, "failed to create static type %#x\n", type);
+
+ /* set icon */
+ g_nReceivedColorStatic = 0;
+ old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
+ ok(!old_image, "got %p\n", old_image);
+ if (type == SS_ICON)
+ ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ else
+ ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+
+ g_nReceivedColorStatic = 0;
+ old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
+ if (type == SS_ICON)
+ {
+ ok(old_image != 0, "got %p\n", old_image);
+ ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ }
+ else
+ {
+ ok(!old_image, "got %p\n", old_image);
+ ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ }
+
+ g_nReceivedColorStatic = 0;
+ old_image = (HICON)SendMessageW(hwnd, STM_SETICON, (WPARAM)icon, 0);
+ if (type == SS_ICON)
+ {
+ ok(old_image != 0, "got %p\n", old_image);
+ ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ }
+ else
+ {
+ ok(!old_image, "got %p\n", old_image);
+ ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ }
+
+ /* set bitmap */
+ g_nReceivedColorStatic = 0;
+ old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
+ ok(!old_image, "got %p\n", old_image);
+ if (type == SS_BITMAP)
+ ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ else
+ ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+
+ g_nReceivedColorStatic = 0;
+ old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)bmp);
+ if (type == SS_BITMAP)
+ {
+ ok(old_image != 0, "got %p\n", old_image);
+ ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ }
+ else
+ {
+ ok(!old_image, "got %p\n", old_image);
+ ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ }
+
+ /* set EMF */
+ g_nReceivedColorStatic = 0;
+ old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)emf);
+ ok(!old_image, "got %p\n", old_image);
+ if (type == SS_ENHMETAFILE)
+ ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ else
+ ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+
+ g_nReceivedColorStatic = 0;
+ old_image = (HICON)SendMessageW(hwnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)emf);
+ if (type == SS_ENHMETAFILE)
+ {
+ ok(old_image != 0, "got %p\n", old_image);
+ ok(g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ }
+ else
+ {
+ ok(!old_image, "got %p\n", old_image);
+ ok(!g_nReceivedColorStatic, "Unexpected WM_CTLCOLORSTATIC value %d\n", g_nReceivedColorStatic);
+ }
+
+ DestroyWindow(hwnd);
+
+ winetest_pop_context();
+ }
+
+ DestroyIcon(icon);
+ DeleteObject(bmp);
+ DeleteEnhMetaFile(emf);
+}
+
START_TEST(static)
{
static const char classname[] = "testclass";
@@ -302,6 +416,7 @@ START_TEST(static)
test_updates(SS_ETCHEDVERT, TODO_COUNT);
test_set_text();
test_set_image();
+ test_STM_SETIMAGE();
DestroyWindow(hMainWnd);
More information about the wine-cvs
mailing list