[PATCH 2/4] Test the way structure size field is validated
Nikolay Sivov
bunglehead at gmail.com
Thu Oct 15 06:37:06 CDT 2009
---
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;
--
1.5.6.5
--=-5YSgzZ1NIIXoAUdZMoNU--
More information about the wine-patches
mailing list