Skip to content

fix(hidpp20): bound feature response and event parsers#553

Open
jelmerdehen wants to merge 1 commit into
PixlOne:mainfrom
jelmerdehen:fix/hidpp20-feature-bounds
Open

fix(hidpp20): bound feature response and event parsers#553
jelmerdehen wants to merge 1 commit into
PixlOne:mainfrom
jelmerdehen:fix/hidpp20-feature-bounds

Conversation

@jelmerdehen
Copy link
Copy Markdown

Summary

The HID++ 2.0 feature parsers index device-supplied response buffers and reports without verifying that enough bytes are present. A buggy or hostile peripheral can return a Short response where a Long was expected and trigger out-of-bounds reads on std::vector::operator[] or report.paramBegin()[N]. Several event parsers also assert on the function id, which is a no-op under NDEBUG.

Files affected:

  • AdjustableDPI (getSensorCount, getDefaultSensorDPI, getSensorDPI)
  • ChangeHost (getHostInfo)
  • DeviceName (getNameLength, _getName chunk loop)
  • FeatureSet (getFeatureCount, getFeature)
  • HiresScroll (getCapabilities, getMode, wheelMovementEvent, ratchetSwitchEvent)
  • ReprogControls (getControlCount, getControlInfo, getControlReporting, divertedButtonEvent, divertedRawXYEvent)
  • Root (_genGetFeatureInfo, ping, getVersion)
  • SmartShift (getStatus, getDefaults, V2 variants, supportsTorque)
  • ThumbWheel (getInfo, getStatus, setStatus, thumbwheelEvent)
  • WirelessDeviceStatus (statusBroadcastEvent)

Fix

Add length checks before each indexed access; replace assert(...) on report function id with throw std::runtime_error. Most files gain a small require_size helper local to the translation unit.

Test plan

  • Builds cleanly.
  • Real Logitech mice still report DPI / SmartShift / hires-scroll correctly.
  • Stub Short responses to Long-expecting parsers and confirm we throw rather than read OOB.

The HID++ 2.0 feature parsers indexed device-supplied response
buffers and HID++ reports without verifying that enough bytes were
present. A buggy or hostile peripheral could return a Short response
where a Long was expected (or vice versa) and trigger out-of-bounds
reads on std::vector::operator[] or on report.paramBegin()[N].

Add length checks before each indexed access in:
  AdjustableDPI, ChangeHost, DeviceName, FeatureSet, HiresScroll,
  ReprogControls, Root, SmartShift, ThumbWheel, WirelessDeviceStatus.

The event parsers (thumbwheelEvent, wheelMovementEvent,
ratchetSwitchEvent, divertedButtonEvent, divertedRawXYEvent,
statusBroadcastEvent) also replace asserts on the function id with
runtime checks, since asserts are removed in NDEBUG builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant