Nikolay Sivov : comctl32/tooltips: Test the way structure size field is validated.
Alexandre Julliard
julliard at winehq.org
Thu Oct 15 08:54:40 CDT 2009
Module: wine
Branch: master
Commit: f394bed5971be188c5a2d0ca823823a11f52db20
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f394bed5971be188c5a2d0ca823823a11f52db20
Author: Nikolay Sivov <bunglehead at gmail.com>
Date: Thu Oct 15 15:37:06 2009 +0400
comctl32/tooltips: Test the way structure size field is validated.
---
dlls/comctl32/tests/tooltips.c | 148 ++++++++++++++++++++++++++++++++++++++++
dlls/comctl32/tooltips.c | 9 +--
2 files changed, 150 insertions(+), 7 deletions(-)
diff --git a/dlls/comctl32/tests/tooltips.c b/dlls/comctl32/tests/tooltips.c
index ddc162a..4014322 100644
--- a/dlls/comctl32/tests/tooltips.c
+++ b/dlls/comctl32/tests/tooltips.c
@@ -23,6 +23,8 @@
#include "wine/test.h"
+#define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got)
+
static void test_create_tooltip(void)
{
HWND parent, hwnd;
@@ -464,6 +466,152 @@ static void test_ttm_gettoolinfo(void)
ok(0xaaaaaaaa == ti.lParam, "Expected 0xaaaaaaaa, got %lx\n", ti.lParam);
DestroyWindow(hwnd);
+
+ /* 1. test size parameter validation rules (ansi messages) */
+ hwnd = CreateWindowExA(0, TOOLTIPS_CLASSA, NULL, 0,
+ 10, 10, 300, 100,
+ NULL, NULL, NULL, 0);
+
+ ti.cbSize = TTTOOLINFOA_V1_SIZE - 1;
+ ti.hwnd = NULL;
+ ti.hinst = GetModuleHandleA(NULL);
+ ti.uFlags = 0;
+ ti.uId = 0x1234ABCD;
+ ti.lpszText = NULL;
+ ti.lParam = 0xdeadbeef;
+ GetClientRect(hwnd, &ti.rect);
+ r = SendMessage(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&ti);
+ ok(r, "Adding the tool to the tooltip failed\n");
+ r = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(1, r);
+
+ ti.cbSize = TTTOOLINFOA_V1_SIZE - 1;
+ ti.hwnd = NULL;
+ ti.uId = 0x1234ABCD;
+ SendMessage(hwnd, TTM_DELTOOLA, 0, (LPARAM)&ti);
+ r = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(0, r);
+
+ ti.cbSize = TTTOOLINFOA_V2_SIZE - 1;
+ ti.hwnd = NULL;
+ ti.hinst = GetModuleHandleA(NULL);
+ ti.uFlags = 0;
+ ti.uId = 0x1234ABCD;
+ ti.lpszText = NULL;
+ ti.lParam = 0xdeadbeef;
+ GetClientRect(hwnd, &ti.rect);
+ r = SendMessage(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&ti);
+ ok(r, "Adding the tool to the tooltip failed\n");
+ r = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(1, r);
+
+ ti.cbSize = TTTOOLINFOA_V2_SIZE - 1;
+ ti.hwnd = NULL;
+ ti.uId = 0x1234ABCD;
+ SendMessage(hwnd, TTM_DELTOOLA, 0, (LPARAM)&ti);
+ r = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(0, r);
+
+ ti.cbSize = TTTOOLINFOA_V2_SIZE + 1;
+ ti.hwnd = NULL;
+ ti.hinst = GetModuleHandleA(NULL);
+ ti.uFlags = 0;
+ ti.uId = 0x1234ABCD;
+ ti.lpszText = NULL;
+ ti.lParam = 0xdeadbeef;
+ GetClientRect(hwnd, &ti.rect);
+ r = SendMessage(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&ti);
+ ok(r, "Adding the tool to the tooltip failed\n");
+ r = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(1, r);
+
+ ti.cbSize = TTTOOLINFOA_V2_SIZE + 1;
+ ti.hwnd = NULL;
+ ti.uId = 0x1234ABCD;
+ SendMessage(hwnd, TTM_DELTOOLA, 0, (LPARAM)&ti);
+ r = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(0, r);
+
+ DestroyWindow(hwnd);
+
+ /* 2. test size parameter validation rules (w-messages) */
+ hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
+ 10, 10, 300, 100,
+ NULL, NULL, NULL, 0);
+ if(!hwnd)
+ {
+ win_skip("CreateWindowExW() not supported. Skipping.\n");
+ return;
+ }
+
+ tiW.cbSize = TTTOOLINFOW_V1_SIZE - 1;
+ tiW.hwnd = NULL;
+ tiW.hinst = GetModuleHandleA(NULL);
+ tiW.uFlags = 0;
+ tiW.uId = 0x1234ABCD;
+ tiW.lpszText = NULL;
+ tiW.lParam = 0xdeadbeef;
+ GetClientRect(hwnd, &tiW.rect);
+ r = SendMessageW(hwnd, TTM_ADDTOOLW, 0, (LPARAM)&tiW);
+ ok(r, "Adding the tool to the tooltip failed\n");
+ r = SendMessageW(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(1, r);
+
+ tiW.cbSize = TTTOOLINFOW_V1_SIZE - 1;
+ tiW.hwnd = NULL;
+ tiW.uId = 0x1234ABCD;
+ SendMessageW(hwnd, TTM_DELTOOLW, 0, (LPARAM)&tiW);
+ r = SendMessageW(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(0, r);
+
+ tiW.cbSize = TTTOOLINFOW_V2_SIZE - 1;
+ tiW.hwnd = NULL;
+ tiW.hinst = GetModuleHandleA(NULL);
+ tiW.uFlags = 0;
+ tiW.uId = 0x1234ABCD;
+ tiW.lpszText = NULL;
+ tiW.lParam = 0xdeadbeef;
+ GetClientRect(hwnd, &tiW.rect);
+ r = SendMessageW(hwnd, TTM_ADDTOOLW, 0, (LPARAM)&tiW);
+ ok(r, "Adding the tool to the tooltip failed\n");
+ r = SendMessageW(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(1, r);
+
+ tiW.cbSize = TTTOOLINFOW_V2_SIZE - 1;
+ tiW.hwnd = NULL;
+ tiW.uId = 0x1234ABCD;
+ SendMessageW(hwnd, TTM_DELTOOLW, 0, (LPARAM)&tiW);
+ r = SendMessageW(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(0, r);
+
+ tiW.cbSize = TTTOOLINFOW_V2_SIZE + 1;
+ tiW.hwnd = NULL;
+ tiW.hinst = GetModuleHandleA(NULL);
+ tiW.uFlags = 0;
+ tiW.uId = 0x1234ABCD;
+ tiW.lpszText = NULL;
+ tiW.lParam = 0xdeadbeef;
+ GetClientRect(hwnd, &tiW.rect);
+ r = SendMessageW(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&tiW);
+ ok(r, "Adding the tool to the tooltip failed\n");
+ r = SendMessageW(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(1, r);
+ /* looks like TTM_DELTOOLW doesn't work with invalid size */
+ tiW.cbSize = TTTOOLINFOW_V2_SIZE + 1;
+ tiW.hwnd = NULL;
+ tiW.uId = 0x1234ABCD;
+ SendMessageW(hwnd, TTM_DELTOOLW, 0, (LPARAM)&tiW);
+ r = SendMessageW(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(1, r);
+
+ tiW.cbSize = TTTOOLINFOW_V2_SIZE;
+ tiW.hwnd = NULL;
+ tiW.uId = 0x1234ABCD;
+ SendMessageW(hwnd, TTM_DELTOOLW, 0, (LPARAM)&tiW);
+ r = SendMessageW(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+ expect(0, r);
+
+ DestroyWindow(hwnd);
}
START_TEST(tooltips)
diff --git a/dlls/comctl32/tooltips.c b/dlls/comctl32/tooltips.c
index 05cd0dc..99656d7 100644
--- a/dlls/comctl32/tooltips.c
+++ b/dlls/comctl32/tooltips.c
@@ -1027,8 +1027,6 @@ TOOLTIPS_AddToolA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
if (lpToolInfo == NULL)
return FALSE;
- if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
- return FALSE;
TRACE("add tool (%p) %p %ld%s!\n",
infoPtr->hwndSelf, lpToolInfo->hwnd, lpToolInfo->uId,
@@ -1116,8 +1114,6 @@ TOOLTIPS_AddToolW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
if (lpToolInfo == NULL)
return FALSE;
- if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
- return FALSE;
TRACE("add tool (%p) %p %ld%s!\n",
infoPtr->hwndSelf, lpToolInfo->hwnd, lpToolInfo->uId,
@@ -1279,8 +1275,6 @@ TOOLTIPS_DelToolA (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
if (lpToolInfo == NULL)
return 0;
- if (lpToolInfo->cbSize < TTTOOLINFOA_V1_SIZE)
- return 0;
if (infoPtr->uNumTools == 0)
return 0;
@@ -1299,7 +1293,8 @@ TOOLTIPS_DelToolW (TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
if (lpToolInfo == NULL)
return 0;
- if (lpToolInfo->cbSize < TTTOOLINFOW_V1_SIZE)
+ if (lpToolInfo->cbSize > TTTOOLINFOW_V2_SIZE &&
+ lpToolInfo->cbSize != TTTOOLINFOW_V3_SIZE)
return 0;
if (infoPtr->uNumTools == 0)
return 0;
More information about the wine-cvs
mailing list