fix(hidpp20): bound feature response and event parsers#553
Open
jelmerdehen wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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[]orreport.paramBegin()[N]. Several event parsers alsoasserton the function id, which is a no-op underNDEBUG.Files affected:
AdjustableDPI(getSensorCount,getDefaultSensorDPI,getSensorDPI)ChangeHost(getHostInfo)DeviceName(getNameLength,_getNamechunk 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 withthrow std::runtime_error. Most files gain a smallrequire_sizehelper local to the translation unit.Test plan