# GHSA-VCF2-Q3RM-GFPQ: Out-of-bounds write in LibOSDP cp\_decode\_response() REPLY\_KEYPAD/REPLY\_RAW handlers due to missing destination-buffer bounds check

- Database: GitHub
- Severity: CVSS 8.1 (High)
- Published: 2026-08-30
- Modified: 2026-08-30

## Affected versions

- libosdp (PyPI): from 1.3.0
- libosdp-sys (crates.io): from 0.1.0

## Description

### Bug class
CWE-787: Out-of-bounds Write (stack). A memory-corruption primitive whose content and length are
attacker-controlled.

### Location
- src/osdp_cp.c, function cp_decode_response(), REPLY_KEYPAD case -- memcpy at src/osdp_cp.c:530
- src/osdp_cp.c, function cp_decode_response(), REPLY_RAW case   -- memcpy at src/osdp_cp.c:547

### Mechanism
cp_decode_response() parses every reply a CP receives from a PD into a local, fixed-size
`struct osdp_event event` (160 bytes) held on the stack.

- REPLY_KEYPAD: a keypress-count byte is read straight off the wire as an unsigned 8-bit value
  (0-255). The only guard is a consistency check that the declared count equals the number of
  payload bytes actually present in the frame. There is NO check that the count is within the
  destination field, which is a fixed 64-byte array (OSDP_EVENT_KEYPRESS_MAX_DATALEN). A frame that
  carries more than 64 payload bytes therefore passes the consistency check and drives a memcpy of
  up to ~245 bytes into the 64-byte field, overrunning the `event` object on the CP stack.
- REPLY_RAW: a 16-bit card-data bit-length is read off the wire and converted to a byte count
  (bits+7)/8. Again the only guard is that the byte count equals the payload bytes present; there is
  NO check against the fixed 64-byte destination (OSDP_EVENT_CARDREAD_MAX_DATALEN). The same overrun
  results.

The asymmetry is the tell: the sibling variable-length handler in the same function (REPLY_MFGREP,
src/osdp_cp.c:575-577) DOES clamp its declared length against its own MAX_DATALEN before copying.
The KEYPAD and RAW handlers omit that clamp. This clamp was never added on any branch (git pickaxe
on the MAX_DATALEN constants shows only the macro split/rename commits, never a bounds fix at these
two sinks).

The upper bound on the copy is the physical-layer packet length (pkt_len <= ~256), so a single frame
yields an overflow of well over 100 bytes past the 64-byte field, past the end of the 160-byte
`event` object and into adjacent stack.

### Impact
- Availability (certain, demonstrated): the overflow reliably corrupts the CP stack. On a normal
  (non-instrumented) build it trips the stack canary and aborts the process ("stack smashing
  detected"), or faults -- a repeatable denial of service of the reader controller, i.e. the device
  that actually unlocks doors.
- Integrity of memory / code execution (feasible, NOT witnessed): the overflow length and content
  are attacker-controlled, so on an embedded CP build without stack canaries / ASLR / W^X -- the
  common no-MMU MCU target for this library -- the write reaches saved state and is a candidate for
  control-flow hijack. Program-counter control is NOT demonstrated here and is not claimed; it is
  integrator- and toolchain-dependent.

### Reachability
- Transport / position: OSDP is an RS-485 serial bus. The attacker must be ON the bus segment: a
  rogue, cloned, or compromised PD; a physically tapped reader wire; or an in-line RS-485 converter
  / serial-to-IP bridge injecting a CRC-valid reply. This is the exact bus-attacker model OSDP
  Secure Channel exists to defend against. Not internet-routable on its own.
- Pre-auth in the default configuration: cp_decode_response() runs on EVERY reply during the normal
  poll cycle. There is NO command-id gate and NO Secure-Channel requirement on the KEYPAD/RAW path
  -- when Secure Channel is not active (the default; OSDP_FLAG_ENFORCE_SECURE unset), plaintext
  replies are decoded directly. No pairing, key, or prior handshake is needed.
- Config-gated when hardened: if the CP is configured with Secure Channel enforced, an attacker
  would need to be inside an established secure session (SCBK), degrading the vector to post-auth.
- On-silicon status: NOT verified on physical CP silicon. Reproduction is host-side against the
  real, unmodified upstream source; the on-device outcome (hard crash vs. watchdog recovery vs.
  further corruption) depends on the target memory map and mitigations.

### CVSS 3.1
Primary (memory corruption, default non-ENFORCE_SECURE CP):
CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:H -- Base 8.1 (High)
- Pure-DoS floor (availability only): CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H -- 6.5 (Medium)
- No-mitigation embedded CP where code execution is feasible: C:H/I:H/A:H -- 8.8 (High)
- ENFORCE_SECURE deployment: PR:H (SCBK required) lowers the score accordingly.

## References

- https://github.com/osdp-dev/libosdp/security/advisories/GHSA-vcf2-q3rm-gfpq

Page: https://cve.now/GHSA-VCF2-Q3RM-GFPQ

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
