From 0aa1af219fd01253fda1724fc1c009e5aba9fa32 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 5 Jun 2015 17:30:28 +0900 Subject: [PATCH] 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 cd3fdd75a4c..ae6b88768d3 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 e3ca808e243..25da45b99c4 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; -- 2.11.4.GIT