Access violation in freerdp_capability_buffer_copy during freerdp_connect after rapid connect/abort cycles
Describe the bug
When rapidly cycling RDP connections (connect → user-initiated disconnect/abort → reconnect) while display reconfiguration happens (DisplayControl monitor layout PDUs, fullscreen ↔ windowed toggles in the client UI), freerdp_connect crashes with an access violation inside the settings clone path, reading a stale ReceivedCapabilityData entry:
(6c98.4d30): Access violation - code c0000005 (first chance)
msvcrt!memcpy+0x104:
movups xmm2,xmmword ptr [rcx+rdx+10h] ds:0000026f`630c0000=????????????????
Child-SP RetAddr Call Site
0000007c`c9dff768 00007ffa`c9058fd2 msvcrt!memcpy+0x104
0000007c`c9dff770 00007ffa`c9059e61 libfreerdp3!freerdp_capability_buffer_copy+0x4e2
0000007c`c9dff7e0 00007ffa`c90c6b9b libfreerdp3!freerdp_settings_set_pointer_len+0x511
0000007c`c9dff850 00007ffa`c90c746c libfreerdp3!freerdp_settings_copy+0x38b
0000007c`c9dff960 00007ffa`c90d7f38 libfreerdp3!freerdp_settings_clone+0x2c
0000007c`c9dff9a0 00007ff6`a52a9757 libfreerdp3!freerdp_connect+0x16d8
0000007c`c9dffb10 00007ffa`ba04fc7f <client>!RdpSession::pumpLoop+0x1c7The memcpy source (src->ReceivedCapabilityData[x], copied via freerdp_capability_buffer_copy() from originalSettings in the rdp_reset_runtime_settings() reconnect path) points to freed/decommitted memory: rdx = 0xfffffffff4e21020 in one dump and 0x2f9e020 in another.
To Reproduce
Custom client using the RDP_CLIENT_ENTRY_POINTS interface (context created via freerdp_client_context_new, settings populated in PreConnect):
- Connect to a Windows 10 x64 RDP server.
- Disconnect (user-initiated,
freerdp_abort_connect_context()). - Reconnect and toggle the display layout while connecting (DisplayControl monitor layout PDUs, fullscreen ↔ windowed changes on the client side).
- Repeat 1–3 quickly. Typically crashes within a handful of cycles inside
freerdp_connect.
With full page heap enabled, the faulting instruction is the first read of the stale capability buffer.
Expected behavior
freerdp_settings_clone() / freerdp_capability_buffer_copy() must not dereference stale ReceivedCapabilityData[] entries after an aborted connection — either the entries are validated/reset when the buffers are freed during teardown, or the clone tolerates dangling entries by resetting ReceivedCapabilitiesSize.
Environment
- OS: Windows 11 24H2 x64
- FreeRDP: 3.31.1 (client library linked into a Qt 6.8.2 application, WIN7 AMD64 build via MinGW)
- Server: Windows 10 Pro x64
- Connection sequence in the reproducer: user-driven disconnect (
freerdp_abort_connect_context()) during/after display reconfiguration, reconnect within seconds
Additional context
- The crash is intermittent but reliably reproducible within a few fast connect/abort cycles.
- Full crash dumps (captured with page heap enabled) and a symbolized client binary are available on request.
Source: FreeRDP/FreeRDP