mirror of
https://github.com/glfw/glfw.git
synced 2026-01-11 23:33:16 +01: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.
This commit is contained in:
@@ -1664,20 +1664,18 @@ void _glfwSetClipboardStringWayland(const char* string)
|
||||
_glfw.wl.dataSource = NULL;
|
||||
}
|
||||
|
||||
if (_glfw.wl.clipboardSendString)
|
||||
char* copy = _glfw_strdup(string);
|
||||
if (!copy)
|
||||
{
|
||||
_glfw_free(_glfw.wl.clipboardSendString);
|
||||
_glfw.wl.clipboardSendString = NULL;
|
||||
}
|
||||
|
||||
_glfw.wl.clipboardSendString = _glfw_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);
|
||||
|
||||
_glfw_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