Nikolay Sivov : comctl32/toolbar: Properly handle invalid arguments processing TB_ADDSTRING message.

Alexandre Julliard julliard at winehq.org
Mon Oct 4 11:04:01 CDT 2010


Module: wine
Branch: master
Commit: f9736bcc6e929b92439486b5e3a093d061d0262a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f9736bcc6e929b92439486b5e3a093d061d0262a

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Sun Oct  3 02:42:50 2010 +0400

comctl32/toolbar: Properly handle invalid arguments processing TB_ADDSTRING message.

---

 dlls/comctl32/tests/toolbar.c |    8 ++++++++
 dlls/comctl32/toolbar.c       |   28 ++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/dlls/comctl32/tests/toolbar.c b/dlls/comctl32/tests/toolbar.c
index 8311df5..87edee1 100644
--- a/dlls/comctl32/tests/toolbar.c
+++ b/dlls/comctl32/tests/toolbar.c
@@ -505,6 +505,14 @@ static void test_add_string(void)
     ok(ret == 2, "TB_ADDSTRINGA - unexpected return %d\n", ret);
     CHECK_STRING_TABLE(3, ret2);
 
+    /* null instance handle */
+    ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0, IDS_TBADD1);
+    ok(ret == -1, "TB_ADDSTRINGA - unexpected return %d\n", ret);
+
+    /* invalid instance handle */
+    ret = SendMessageA(hToolbar, TB_ADDSTRINGA, 0xdeadbeef, IDS_TBADD1);
+    ok(ret == -1, "TB_ADDSTRINGA - unexpected return %d\n", ret);
+
     ret = SendMessageA(hToolbar, TB_ADDSTRINGA, (WPARAM)GetModuleHandle(NULL), IDS_TBADD1);
     ok(ret == 3, "TB_ADDSTRINGA - unexpected return %d\n", ret);
     CHECK_STRING_TABLE(3, ret2);
diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 9b41732..880477e 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -2900,13 +2900,27 @@ TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
     BOOL fFirstString = (infoPtr->nNumStrings == 0);
     INT nIndex = infoPtr->nNumStrings;
 
-    if (hInstance && IS_INTRESOURCE(lParam)) {
+    TRACE("%p, %lx\n", hInstance, lParam);
+
+    if (IS_INTRESOURCE(lParam)) {
 	WCHAR szString[MAX_RESOURCE_STRING_LENGTH];
 	WCHAR delimiter;
 	WCHAR *next_delim;
+        HRSRC hrsrc;
 	WCHAR *p;
 	INT len;
-	TRACE("adding string from resource!\n");
+
+	TRACE("adding string from resource\n");
+
+        if (!hInstance) return -1;
+
+        hrsrc = FindResourceW( hInstance, MAKEINTRESOURCEW((LOWORD(lParam) >> 4) + 1),
+                               (LPWSTR)RT_STRING );
+        if (!hrsrc)
+        {
+            TRACE("string not found in resources\n");
+            return -1;
+        }
 
         len = LoadStringW (hInstance, (UINT)lParam,
                              szString, MAX_RESOURCE_STRING_LENGTH);
@@ -2915,7 +2929,7 @@ TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
         if (len == 0 || len == 1)
             return nIndex;
 
-        TRACE("Delimiter: 0x%x\n", *szString);
+        TRACE("delimiter: 0x%x\n", *szString);
         delimiter = *szString;
         p = szString + 1;
 
@@ -2941,7 +2955,7 @@ TOOLBAR_AddStringW (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
 
 	if (p == NULL)
 	    return -1;
-	TRACE("adding string(s) from array!\n");
+	TRACE("adding string(s) from array\n");
 	while (*p) {
             len = strlenW (p);
 
@@ -2968,14 +2982,16 @@ TOOLBAR_AddStringA (TOOLBAR_INFO *infoPtr, HINSTANCE hInstance, LPARAM lParam)
     INT nIndex;
     INT len;
 
-    if (hInstance && IS_INTRESOURCE(lParam))  /* load from resources */
+    TRACE("%p, %lx\n", hInstance, lParam);
+
+    if (IS_INTRESOURCE(lParam))  /* load from resources */
         return TOOLBAR_AddStringW(infoPtr, hInstance, lParam);
 
     p = (LPSTR)lParam;
     if (p == NULL)
         return -1;
 
-    TRACE("adding string(s) from array!\n");
+    TRACE("adding string(s) from array\n");
     nIndex = infoPtr->nNumStrings;
     while (*p) {
         len = strlen (p);




More information about the wine-cvs mailing list