Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorJesse Yurkovich <jesse.y@gmail.com>2022-05-28 06:52:52 +0300
committerJesse Yurkovich <jesse.y@gmail.com>2022-05-28 06:52:52 +0300
commit3f1f4df3fd9b37fb97fbf4632725032de87d0828 (patch)
tree866fbfe45535bbb5aac5bf9296d8145ca6405db4 /intern
parent712b0496c17c442a046cb76db7823d19e50a3892 (diff)
Fix unreported misuse of Win32 clipboard API
An ASAN build highlighted a longstanding bug during ctrl+c operations inside various text widgets. The existing code had mismatched memory lock/unlock calls and was using the wrong allocator. Fix the code surrounding `SetClipboardData` to be correct per MSDN: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setclipboarddata Differential Revision: https://developer.blender.org/D15039
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 8e07bf4ea3d..28c86db53e2 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -2211,31 +2211,28 @@ char *GHOST_SystemWin32::getClipboard(bool selection) const
void GHOST_SystemWin32::putClipboard(const char *buffer, bool selection) const
{
- if (selection) {
+ if (selection || !buffer) {
return;
} // for copying the selection, used on X11
if (OpenClipboard(NULL)) {
- HLOCAL clipbuffer;
- wchar_t *data;
+ EmptyClipboard();
- if (buffer) {
- size_t len = count_utf_16_from_8(buffer);
- EmptyClipboard();
+ // Get length of buffer including the terminating null
+ size_t len = count_utf_16_from_8(buffer);
- clipbuffer = LocalAlloc(LMEM_FIXED, sizeof(wchar_t) * len);
- data = (wchar_t *)GlobalLock(clipbuffer);
+ HGLOBAL clipbuffer = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * len);
+ if (clipbuffer) {
+ wchar_t *data = (wchar_t *)GlobalLock(clipbuffer);
conv_utf_8_to_16(buffer, data, len);
- LocalUnlock(clipbuffer);
+ GlobalUnlock(clipbuffer);
SetClipboardData(CF_UNICODETEXT, clipbuffer);
}
+
CloseClipboard();
}
- else {
- return;
- }
}
/* -------------------------------------------------------------------- */