[2/2] comctl32/treeview: Check passed handle value in WM_COMMAND handler

Nikolay Sivov bunglehead at gmail.com
Thu Aug 6 15:23:14 CDT 2009


Changelog:
    - Check passed handle value in WM_COMMAND handler

>From 7bb0465aad35e2054aaefab22656974073c1f73a Mon Sep 17 00:00:00 2001
From: Nikolay Sivov <bunglehead at gmail.com>
Date: Fri, 7 Aug 2009 00:13:25 +0400
Subject: Check passed handle value in WM_COMMAND handler

---
 dlls/comctl32/tests/treeview.c |   16 ++++++++++++++++
 dlls/comctl32/treeview.c       |    7 +++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c
index 7c86450..5cfaf20 100644
--- a/dlls/comctl32/tests/treeview.c
+++ b/dlls/comctl32/tests/treeview.c
@@ -879,9 +879,25 @@ static void test_itemedit(void)
     /* item shouldn't be selected automatically after TVM_EDITLABEL */
     r = SendMessage(hTree, TVM_GETITEMSTATE, (WPARAM)hRoot, TVIS_SELECTED);
     expect(0, r);
+    /* try to cancel with wrong edit handle */
+    r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)NULL);
+    expect(0, r);
+    ok(IsWindow(edit), "Expected edit control to be valid\n");
     r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
     expect(0, r);
     ok(!IsWindow(edit), "Expected edit control to be destroyed\n");
+    /* try to cancel without creating edit */
+    r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)NULL);
+    expect(0, r);
+
+    /* try to cancel with wrong (not null) handle */
+    edit = (HWND)SendMessage(hTree, TVM_EDITLABEL, 0, (LPARAM)hRoot);
+    ok(IsWindow(edit), "Expected valid handle\n");
+    r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)hTree);
+    expect(0, r);
+    ok(IsWindow(edit), "Expected edit control to be valid\n");
+    r = SendMessage(hTree, WM_COMMAND, MAKEWPARAM(0, EN_KILLFOCUS), (LPARAM)edit);
+    expect(0, r);
 
     /* remove selection after starting edit */
     r = TreeView_SelectItem(hTree, hRoot);
diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c
index 44bb841..a38434d 100644
--- a/dlls/comctl32/treeview.c
+++ b/dlls/comctl32/treeview.c
@@ -3651,8 +3651,11 @@ TREEVIEW_Command(TREEVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
 	    break;
 	}
     case EN_KILLFOCUS:
-        TREEVIEW_EndEditLabelNow(infoPtr, FALSE);
-        break;
+	/* apparently we should respect passed handle value */
+	if (infoPtr->hwndEdit != (HWND)lParam) return FALSE;
+
+	TREEVIEW_EndEditLabelNow(infoPtr, FALSE);
+	break;
 
     default:
 	return SendMessageW(infoPtr->hwndNotify, WM_COMMAND, wParam, lParam);
-- 
1.5.6.5





More information about the wine-patches mailing list