mirror of
https://github.com/glfw/glfw.git
synced 2026-09-17 22:32:50 +00:00
Wayland: Fix handling of clipboard set to self
Passing any part of the result of glfwGetClipboardString to
glfwSetClipboardString would result in, at best, a use-after-free error.
(cherry picked from commit 9c95cfb9f1)
This commit is contained in:
+9
-11
@@ -1798,20 +1798,18 @@ void _glfwPlatformSetClipboardString(const char* string)
|
||||
_glfw.wl.dataSource = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.wl.clipboardSendString)
|
||||
char* copy = _glfw_strdup(string);
|
||||
if (!copy)
|
||||
{
|
||||
free(_glfw.wl.clipboardSendString);
|
||||
_glfw.wl.clipboardSendString = NULL;
|
||||
}
|
||||
|
||||
_glfw.wl.clipboardSendString = strdup(string);
|
||||
if (!_glfw.wl.clipboardSendString)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"Wayland: Impossible to allocate clipboard string");
|
||||
_glfwInputError(GLFW_OUT_OF_MEMORY,
|
||||
"Wayland: Failed to allocate clipboard string");
|
||||
return;
|
||||
}
|
||||
_glfw.wl.clipboardSendSize = strlen(string);
|
||||
|
||||
free(_glfw.wl.clipboardSendString);
|
||||
_glfw.wl.clipboardSendString = copy;
|
||||
|
||||
_glfw.wl.clipboardSendSize = strlen(_glfw.wl.clipboardSendString);
|
||||
_glfw.wl.dataSource =
|
||||
wl_data_device_manager_create_data_source(_glfw.wl.dataDeviceManager);
|
||||
if (!_glfw.wl.dataSource)
|
||||
|
||||
Reference in New Issue
Block a user