Alexandre Julliard : user32: Disallow format 0 in SetClipboardData.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jun 5 06:46:11 CDT 2015


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Jun  5 17:30:28 2015 +0900

user32: Disallow format 0 in SetClipboardData.

---

 dlls/user32/clipboard.c       |  6 ++++++
 dlls/user32/tests/clipboard.c | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/dlls/user32/clipboard.c b/dlls/user32/clipboard.c
index cd3fdd75..ae6b887 100644
--- a/dlls/user32/clipboard.c
+++ b/dlls/user32/clipboard.c
@@ -400,6 +400,12 @@ HANDLE WINAPI SetClipboardData(UINT wFormat, HANDLE hData)
 
     TRACE("(%04X, %p) !\n", wFormat, hData);
 
+    if (!wFormat)
+    {
+        SetLastError( ERROR_CLIPBOARD_NOT_OPEN );
+        return 0;
+    }
+
     /* If it's not owned, data can only be set if the format isn't
        available and its rendering is not delayed */
     if (!CLIPBOARD_GetClipboardInfo(&cbinfo) ||
diff --git a/dlls/user32/tests/clipboard.c b/dlls/user32/tests/clipboard.c
index e3ca808..25da45b 100644
--- a/dlls/user32/tests/clipboard.c
+++ b/dlls/user32/tests/clipboard.c
@@ -111,6 +111,7 @@ static void test_RegisterClipboardFormatA(void)
     char buf[256];
     int len;
     BOOL ret;
+    HANDLE handle;
 
     format_id = RegisterClipboardFormatA("my_cool_clipboard_format");
     ok(format_id > 0xc000 && format_id < 0xffff, "invalid clipboard format id %04x\n", format_id);
@@ -165,6 +166,25 @@ todo_wine
     ret = OpenClipboard(0);
     ok( ret, "OpenClipboard error %d\n", GetLastError());
 
+    /* try some invalid/unregistered formats */
+    SetLastError( 0xdeadbeef );
+    handle = SetClipboardData( 0, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 ));
+    ok( !handle, "SetClipboardData succeeded\n" );
+    ok( GetLastError() == ERROR_CLIPBOARD_NOT_OPEN, "wrong error %u\n", GetLastError());
+    handle = SetClipboardData( 0x1234, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 ));
+    ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError());
+    handle = SetClipboardData( 0x123456, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 ));
+    ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError());
+    handle = SetClipboardData( 0xffff8765, GlobalAlloc( GMEM_DDESHARE | GMEM_MOVEABLE, 1 ));
+    ok( handle != 0, "SetClipboardData failed err %d\n", GetLastError());
+
+    ok( IsClipboardFormatAvailable( 0x1234 ), "format missing\n" );
+    ok( IsClipboardFormatAvailable( 0x123456 ), "format missing\n" );
+    ok( IsClipboardFormatAvailable( 0xffff8765 ), "format missing\n" );
+    ok( !IsClipboardFormatAvailable( 0 ), "format available\n" );
+    ok( !IsClipboardFormatAvailable( 0x3456 ), "format available\n" );
+    ok( !IsClipboardFormatAvailable( 0x8765 ), "format available\n" );
+
     trace("# of formats available: %d\n", CountClipboardFormats());
 
     format_id = 0;




More information about the wine-cvs mailing list