address copilot review findings in wf_cliprdr.c

- Reject a negative FILECONTENTS_SIZE result: m_lSize is unsigned, so a
  negative value became a huge bogus stream size that keeps reads going.
- Use a unique per-stream counter as the CLIPRDR streamId instead of a
  truncated IStream pointer, which could collide or be reused after free
  (and leaked heap addresses to the peer).
- Add req_f_request_mutex to serialize whole file-contents request/response
  cycles, enforcing the previously assumed one-outstanding-request
  invariant when multiple streams are read concurrently. Bounded acquire
  so a wedged request fails the read instead of hanging a consumer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
rustdesk
2026-07-04 17:31:26 +08:00
parent 1c2188f80b
commit bb8ffef7f0
2 changed files with 66 additions and 22 deletions

View File

@@ -84,8 +84,7 @@ START_TEST(test_file_contents_request_initializes_optional_fields)
ck_assert_ptr_nonnull(clipboard.req_f_mutex);
ck_assert_ptr_nonnull(clipboard.req_fevent);
rc = cliprdr_send_request_filecontents(&clipboard, 1, (const void *)(ULONG_PTR)7,
0, FILECONTENTS_SIZE, 0, 0, 0);
rc = cliprdr_send_request_filecontents(&clipboard, 1, 7, 0, FILECONTENTS_SIZE, 0, 0, 0);
ck_assert_int_eq(rc, CHANNEL_RC_OK);
ck_assert_int_eq(clipboard.req_f_stream_id_expected, 7);