comctl32/tooltips: Fix an obviously wrong structure size check.
authorNikolay Sivov <bunglehead@gmail.com>
Thu, 15 Oct 2009 10:49:30 +0000 (14:49 +0400)
committerAlexandre Julliard <julliard@winehq.org>
Thu, 15 Oct 2009 12:10:32 +0000 (14:10 +0200)
dlls/comctl32/tests/tooltips.c
dlls/comctl32/tooltips.c
include/commctrl.h

index b8c46cb52cbc0b9591cfde568f31389e17e65bbf..ddc162ac58265eedaf270ca8fbd54b194f45a6f3 100644 (file)
@@ -416,6 +416,56 @@ static void test_gettext(void)
     DestroyWindow(hwnd);
 }
 
+static void test_ttm_gettoolinfo(void)
+{
+    TTTOOLINFOA ti;
+    TTTOOLINFOW tiW;
+    HWND hwnd;
+    DWORD r;
+
+    hwnd = CreateWindowExA(0, TOOLTIPS_CLASSA, NULL, 0,
+                           10, 10, 300, 100,
+                           NULL, NULL, NULL, 0);
+
+    ti.cbSize = TTTOOLINFOA_V2_SIZE;
+    ti.hwnd = NULL;
+    ti.hinst = GetModuleHandleA(NULL);
+    ti.uFlags = 0;
+    ti.uId = 0x1234ABCD;
+    ti.lpszText = NULL;
+    ti.lParam = 0xdeadbeef;
+    GetClientRect(hwnd, &ti.rect);
+    r = SendMessageA(hwnd, TTM_ADDTOOLA, 0, (LPARAM)&ti);
+    ok(r, "Adding the tool to the tooltip failed\n");
+
+    ti.cbSize = TTTOOLINFOA_V2_SIZE;
+    ti.lParam = 0xaaaaaaaa;
+    r = SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&ti);
+    ok(r, "Getting tooltip info failed\n");
+    ok(0xdeadbeef == ti.lParam, "Expected 0xdeadbeef, got %lx\n", ti.lParam);
+
+    tiW.cbSize = TTTOOLINFOW_V2_SIZE;
+    tiW.hwnd = NULL;
+    tiW.uId = 0x1234ABCD;
+    tiW.lParam = 0xaaaaaaaa;
+    r = SendMessageA(hwnd, TTM_GETTOOLINFOW, 0, (LPARAM)&tiW);
+    ok(r, "Getting tooltip info failed\n");
+    ok(0xdeadbeef == tiW.lParam, "Expected 0xdeadbeef, got %lx\n", tiW.lParam);
+
+    ti.cbSize = TTTOOLINFOA_V2_SIZE;
+    ti.uId = 0x1234ABCD;
+    ti.lParam = 0xaaaaaaaa;
+    r = SendMessageA(hwnd, TTM_SETTOOLINFOA, 0, (LPARAM)&ti);
+
+    ti.cbSize = TTTOOLINFOA_V2_SIZE;
+    ti.lParam = 0xdeadbeef;
+    r = SendMessageA(hwnd, TTM_GETTOOLINFOA, 0, (LPARAM)&ti);
+    ok(r, "Getting tooltip info failed\n");
+    ok(0xaaaaaaaa == ti.lParam, "Expected 0xaaaaaaaa, got %lx\n", ti.lParam);
+
+    DestroyWindow(hwnd);
+}
+
 START_TEST(tooltips)
 {
     InitCommonControls();
@@ -423,4 +473,5 @@ START_TEST(tooltips)
     test_create_tooltip();
     test_customdraw();
     test_gettext();
+    test_ttm_gettoolinfo();
 }
index 54600e81c8774265b4818c6f97cd4c482a08c802..05cd0dc3c2a6a487a94c8ba6d11694c8d0bd88f3 100644 (file)
@@ -1076,7 +1076,7 @@ TOOLTIPS_AddToolA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
        }
     }
 
-    if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
+    if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
        toolPtr->lParam = lpToolInfo->lParam;
 
     /* install subclassing hook */
@@ -1164,7 +1164,7 @@ TOOLTIPS_AddToolW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
        }
     }
 
-    if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
+    if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
        toolPtr->lParam = lpToolInfo->lParam;
 
     /* install subclassing hook */
@@ -1337,7 +1337,7 @@ TOOLTIPS_EnumToolsA (const TOOLTIPS_INFO *infoPtr, UINT uIndex, LPTTTOOLINFOA lp
 /*    lpToolInfo->lpszText = toolPtr->lpszText; */
     lpToolInfo->lpszText = NULL;  /* FIXME */
 
-    if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
+    if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
        lpToolInfo->lParam = toolPtr->lParam;
 
     return TRUE;
@@ -1369,7 +1369,7 @@ TOOLTIPS_EnumToolsW (const TOOLTIPS_INFO *infoPtr, UINT uIndex, LPTTTOOLINFOW lp
 /*    lpToolInfo->lpszText = toolPtr->lpszText; */
     lpToolInfo->lpszText = NULL;  /* FIXME */
 
-    if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
+    if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
        lpToolInfo->lParam = toolPtr->lParam;
 
     return TRUE;
@@ -1416,7 +1416,7 @@ TOOLTIPS_GetCurrentToolA (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo
 /*         lpToolInfo->lpszText = toolPtr->lpszText; */
            lpToolInfo->lpszText = NULL;  /* FIXME */
 
-           if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
+           if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
                lpToolInfo->lParam = toolPtr->lParam;
 
            return TRUE;
@@ -1448,7 +1448,7 @@ TOOLTIPS_GetCurrentToolW (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo
 /*         lpToolInfo->lpszText = toolPtr->lpszText; */
            lpToolInfo->lpszText = NULL;  /* FIXME */
 
-           if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
+           if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
                lpToolInfo->lParam = toolPtr->lParam;
 
            return TRUE;
@@ -1602,7 +1602,7 @@ TOOLTIPS_GetToolInfoA (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOA lpToolInfo)
 /*    lpToolInfo->lpszText = toolPtr->lpszText; */
     lpToolInfo->lpszText = NULL;  /* FIXME */
 
-    if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
+    if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
        lpToolInfo->lParam = toolPtr->lParam;
 
     return TRUE;
@@ -1637,7 +1637,7 @@ TOOLTIPS_GetToolInfoW (const TOOLTIPS_INFO *infoPtr, LPTTTOOLINFOW lpToolInfo)
 /*    lpToolInfo->lpszText = toolPtr->lpszText; */
     lpToolInfo->lpszText = NULL;  /* FIXME */
 
-    if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
+    if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
        lpToolInfo->lParam = toolPtr->lParam;
 
     return TRUE;
@@ -1660,7 +1660,7 @@ TOOLTIPS_HitTestA (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOA lptthit)
     TRACE("tool %d!\n", nTool);
 
     /* copy tool data */
-    if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOA)) {
+    if (lptthit->ti.cbSize >= TTTOOLINFOA_V1_SIZE) {
        toolPtr = &infoPtr->tools[nTool];
 
        lptthit->ti.uFlags   = toolPtr->uFlags;
@@ -1670,7 +1670,8 @@ TOOLTIPS_HitTestA (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOA lptthit)
        lptthit->ti.hinst    = toolPtr->hinst;
 /*     lptthit->ti.lpszText = toolPtr->lpszText; */
        lptthit->ti.lpszText = NULL;  /* FIXME */
-       lptthit->ti.lParam   = toolPtr->lParam;
+       if (lptthit->ti.cbSize >= TTTOOLINFOA_V2_SIZE)
+           lptthit->ti.lParam   = toolPtr->lParam;
     }
 
     return TRUE;
@@ -1693,7 +1694,7 @@ TOOLTIPS_HitTestW (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit)
     TRACE("tool %d!\n", nTool);
 
     /* copy tool data */
-    if (lptthit->ti.cbSize >= sizeof(TTTOOLINFOW)) {
+    if (lptthit->ti.cbSize >= TTTOOLINFOW_V1_SIZE) {
        toolPtr = &infoPtr->tools[nTool];
 
        lptthit->ti.uFlags   = toolPtr->uFlags;
@@ -1703,7 +1704,8 @@ TOOLTIPS_HitTestW (const TOOLTIPS_INFO *infoPtr, LPTTHITTESTINFOW lptthit)
        lptthit->ti.hinst    = toolPtr->hinst;
 /*     lptthit->ti.lpszText = toolPtr->lpszText; */
        lptthit->ti.lpszText = NULL;  /* FIXME */
-       lptthit->ti.lParam   = toolPtr->lParam;
+       if (lptthit->ti.cbSize >= TTTOOLINFOW_V2_SIZE)
+           lptthit->ti.lParam   = toolPtr->lParam;
     }
 
     return TRUE;
@@ -2018,7 +2020,7 @@ TOOLTIPS_SetToolInfoA (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOA *lpToolInfo)
        }
     }
 
-    if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOA))
+    if (lpToolInfo->cbSize >= TTTOOLINFOA_V2_SIZE)
        toolPtr->lParam = lpToolInfo->lParam;
 
     return 0;
@@ -2072,7 +2074,7 @@ TOOLTIPS_SetToolInfoW (TOOLTIPS_INFO *infoPtr, const TTTOOLINFOW *lpToolInfo)
        }
     }
 
-    if (lpToolInfo->cbSize >= sizeof(TTTOOLINFOW))
+    if (lpToolInfo->cbSize >= TTTOOLINFOW_V2_SIZE)
        toolPtr->lParam = lpToolInfo->lParam;
 
     if (infoPtr->nCurrentTool == nTool)
index 2add8b8c1495cfe222663dffa812b2c4198a9a3f..f2ea3aeefdddd9f2cf5e1c20d846da1044131daa 100644 (file)
@@ -1774,6 +1774,10 @@ typedef struct tagTOOLINFOW {
 #define TTTOOLINFOA_V1_SIZE CCSIZEOF_STRUCT(TTTOOLINFOA, lpszText)
 #define TTTOOLINFOW_V1_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lpszText)
 #define TTTOOLINFO_V1_SIZE  CCSIZEOF_STRUCT(WINELIB_NAME_AW(TTTOOLINFO), lpszText)
+#define TTTOOLINFOA_V2_SIZE CCSIZEOF_STRUCT(TTTOOLINFOA, lParam)
+#define TTTOOLINFOW_V2_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lParam)
+#define TTTOOLINFOA_V3_SIZE CCSIZEOF_STRUCT(TTTOOLINFOA, lpReserved)
+#define TTTOOLINFOW_V3_SIZE CCSIZEOF_STRUCT(TTTOOLINFOW, lpReserved)
 
 typedef struct _TT_HITTESTINFOA
 {