fix(clipboard,enigo): bound served-list reads, clamp absolute moves

wf_cliprdr: the served-list branch runs before the ownership check, yet it
allocated the peer's cbRequested (up to 4 GiB) before looking the list up.
Accept only FILECONTENTS_SIZE or a range of at most 16 MiB there, which is
all that clients sending an id ever request, and fail anything else before
allocating.

enigo: clamp the scaled absolute coordinate to 0..=65535, the range
MOUSEEVENTF_ABSOLUTE takes, instead of to the i32 range. Coordinates on the
virtual desktop give the same result as before; off-desktop ones now land on
its edge.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
rustdesk
2026-09-24 18:01:24 +08:00
co-authored by Claude Opus 5.5
parent 4b5b3bc497
commit f72946d71c
2 changed files with 12 additions and 4 deletions
+9 -2
View File
@@ -57,8 +57,9 @@
/* File lists kept after they were sent, so a transfer still in flight keeps reading its own
* files after a later copy or paste replaces them. */
#define WF_CLIPRDR_SERVED_FILE_LISTS 4u
/* Largest range the unix file server serves in one request (MAX_RANGE_READ in
* serv_files.rs); larger IStream reads are split into requests of this size. */
/* Largest range served in one request: by the unix file server (MAX_RANGE_READ in
* serv_files.rs) and by the served-list path here. Larger IStream reads are split into
* requests of this size. */
#define WF_CLIPRDR_MAX_RANGE_READ (16u * 1024u * 1024u)
static const WCHAR WF_CLIPRDR_SUPERSCRIPT_DIGITS[] = L"\x00B9\x00B2\x00B3";
static const WCHAR WF_CLIPRDR_INVALID_FILE_NAME_CHARS[] = L"<>:\"|?*";
@@ -3658,6 +3659,12 @@ wf_cliprdr_server_file_contents_request(CliprdrClientContext *context,
is_set_by_instance(clipboard) || is_file_descriptor_from_remote()))
{
ZeroMemory(&vStgMedium, sizeof(STGMEDIUM)); // read at exit
// Clients that send an id split reads to WF_CLIPRDR_MAX_RANGE_READ; refuse anything
// else before allocating what the peer asked for.
if (fileContentsRequest->dwFlags != FILECONTENTS_SIZE &&
(fileContentsRequest->dwFlags != FILECONTENTS_RANGE ||
fileContentsRequest->cbRequested > WF_CLIPRDR_MAX_RANGE_READ))
goto exit;
cbRequested = fileContentsRequest->dwFlags == FILECONTENTS_SIZE
? sizeof(UINT64)
: fileContentsRequest->cbRequested;
+3 -2
View File
@@ -39,14 +39,15 @@ fn mouse_event(flags: u32, data: u32, dx: i32, dy: i32) -> DWORD {
unsafe { SendInput(1, &mut input as LPINPUT, size_of::<INPUT>() as c_int) }
}
// `v` comes from the remote peer unchecked, so scale in i64 to avoid overflow.
// `v` comes from the remote peer unchecked, so scale in i64 to avoid overflow, and clamp to
// the 0..=65535 range MOUSEEVENTF_ABSOLUTE takes.
// `extent` is 0 when the virtual screen metrics are unavailable.
fn to_absolute(v: i32, origin: i32, extent: i32) -> Option<i32> {
if extent <= 0 {
return None;
}
let abs = (v as i64 - origin as i64) * 65535 / extent as i64;
Some(abs.clamp(i32::MIN as i64, i32::MAX as i64) as i32)
Some(abs.clamp(0, 65535) as i32)
}
fn keybd_event(mut flags: u32, vk: u16, scan: u16) -> DWORD {