Dmitry Timoshkov : user32: 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: be8501ac6f1ecfa0e0e86a829939947f0cb82e7d
URL: https://source.winehq.org/git/wine.git/?a=commit;h=be8501ac6f1ecfa0e0e86a829939947f0cb82e7d
Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date: Wed Aug 18 12:36:32 2021 +0300
user32: 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/user32/static.c | 7 +--
dlls/user32/tests/static.c | 121 +++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 122 insertions(+), 6 deletions(-)
diff --git a/dlls/user32/static.c b/dlls/user32/static.c
index 72e49e15e8f..35bdc2490c0 100644
--- a/dlls/user32/static.c
+++ b/dlls/user32/static.c
@@ -103,7 +103,6 @@ static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
HICON prevIcon;
SIZE size;
- if ((style & SS_TYPEMASK) != SS_ICON) return 0;
if (hicon && !get_icon_size( hicon, &size ))
{
WARN("hicon != 0, but invalid\n");
@@ -138,7 +137,6 @@ static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
{
HBITMAP hOldBitmap;
- if ((style & SS_TYPEMASK) != SS_BITMAP) return 0;
if (hBitmap && GetObjectType(hBitmap) != OBJ_BITMAP) {
WARN("hBitmap != 0, but it's not a bitmap\n");
return 0;
@@ -174,7 +172,6 @@ static HBITMAP STATIC_SetBitmap( HWND hwnd, HBITMAP hBitmap, DWORD style )
*/
static HENHMETAFILE STATIC_SetEnhMetaFile( HWND hwnd, HENHMETAFILE hEnhMetaFile, DWORD style )
{
- 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");
return 0;
@@ -501,13 +498,16 @@ LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
case STM_SETIMAGE:
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:
@@ -518,6 +518,7 @@ LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam
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/user32/tests/static.c b/dlls/user32/tests/static.c
index 0c453d08a67..731e0f5df72 100644
--- a/dlls/user32/tests/static.c
+++ b/dlls/user32/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 "wine/test.h"
@@ -189,6 +191,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 = build_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 szClassName[] = "testclass";
@@ -222,6 +336,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