[PATCH 2/4] Test the way structure size field is validated

Nikolay Sivov bunglehead at gmail.com
Wed Oct 14 16:37:34 CDT 2009


---
 dlls/comctl32/tests/tooltips.c |  143 +++++++++++++++++++++++++++++++++++++++-
 dlls/comctl32/tooltips.c       |    9 +--
 2 files changed, 144 insertions(+), 8 deletions(-)

diff --git a/dlls/comctl32/tests/tooltips.c b/dlls/comctl32/tests/tooltips.c
index ae7b771..f3722cd 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;
@@ -460,10 +462,149 @@ static void test_ttm_gettoolinfo(void)
     ti.cbSize = TTTOOLINFOA_V2_SIZE;
     ti.lParam = 0xdeadbeef;
     r = SendMessageW(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&ti);
-    ok(r, "Adding the tool to the tooltip failed\n");
+    ok(r, "Getting tool info failed\n");
     ok(0xaaaaaaaa == ti.lParam, "Expected 0xdeadbeef, 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 = SendMessageW(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 = SendMessageW(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 = SendMessageW(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);
+
+    /* 2. test size parameter validation rules (w-messages) */
+    hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
+                           10, 10, 300, 100,
+                           NULL, NULL, NULL, 0);
+
+    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 = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+    expect(1, r);
+
+    tiW.cbSize = TTTOOLINFOW_V1_SIZE - 1;
+    tiW.hwnd = NULL;
+    tiW.uId = 0x1234ABCD;
+    SendMessage(hwnd, TTM_DELTOOLW, 0, (LPARAM)&tiW);
+    r = SendMessage(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 = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+    expect(1, r);
+
+    tiW.cbSize = TTTOOLINFOW_V2_SIZE - 1;
+    tiW.hwnd = NULL;
+    tiW.uId = 0x1234ABCD;
+    SendMessage(hwnd, TTM_DELTOOLW, 0, (LPARAM)&tiW);
+    r = SendMessage(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 = SendMessage(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;
+    SendMessage(hwnd, TTM_DELTOOLW, 0, (LPARAM)&tiW);
+    r = SendMessage(hwnd, TTM_GETTOOLCOUNT, 0, 0);
+    expect(1, r);
+
+    tiW.cbSize = TTTOOLINFOW_V2_SIZE;
+    tiW.hwnd = NULL;
+    tiW.uId = 0x1234ABCD;
+    SendMessage(hwnd, TTM_DELTOOLW, 0, (LPARAM)&tiW);
+    r = SendMessage(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 6b483df..58f15a5 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


--=-0+yu+2tuRacyczJ6LrY0--




More information about the wine-patches mailing list