Fix undefined behaviour and error handling in the HidModifier config path - #81
Open
nutbolt9 wants to merge 1 commit into
Open
Fix undefined behaviour and error handling in the HidModifier config path#81nutbolt9 wants to merge 1 commit into
nutbolt9 wants to merge 1 commit into
Conversation
The hook read data[0] and wrote data[1..2] without checking length. length is a size_t, so a caller passing 0 or 1 also underflowed the (length - 2) used to size the chunk copy, producing a negative toCopy that memcpy takes as a very large size_t. driver_lighthouse supplies 65 in practice, so this is hardening rather than an observed fault, but the hook runs for every hid_get_feature_report call in that module and the failure mode is heap corruption. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
nutbolt9
force-pushed
the
fix/hid-config-roundtrip
branch
from
August 11, 2026 10:23
03cb3a1 to
650913b
Compare
Author
|
Rebased onto current The two other fixes it originally carried are already covered on
So this is down to the one remaining item.
+4 −1, one file. Happy to drop it if you'd rather not carry the check. |
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.
Three independent fixes in HidModifier, found while investigating a Dream Air that intermittently failed to enumerate. Each is a separate commit.
Uninitialised HidDeviceInfo members (e450067)
AddDevice default-initialises a HidDeviceInfo, so newLighthouseConfig, newLighthouseConfigLength and newLighthouseConfigOffset are indeterminate. ReadLighthouseConfig only assigns newLighthouseConfig on the path where it rewrites the config, so all three early returns — failed feature report, size > 20000, failed decompress — leave the pointer holding stack garbage. HidGetFeatureReportHook then tests it against nullptr and memcpys from it, and Delete() passes it to delete[].
This is reachable in practice: a driver log showing Failed to decompress lighthouse config was immediately followed by Driver lighthouse has no suitable devices and VRInitError_Init_HmdNotFound.
Failed recompression served anyway (b34102f)
compress() returning non-Z_OK was logged, but execution continued and assigned the partially written buffer to info.newLighthouseConfig. The hook then served that to driver_lighthouse in place of the device's own config, so a failed recompress produced a corrupt config rather than no change. Now the buffer is freed and newLighthouseConfig left null, so the hook passes through to the original.
Short-buffer guard in HidGetFeatureReportHook (03cb3a1)
The hook read data[0] and wrote data[1..2] without checking length. Since length is a size_t, a caller passing 0 or 1 also underflows the (length - 2) that sizes the chunk copy, giving a negative toCopy that memcpy takes as a huge value. driver_lighthouse supplies 65 in practice, so this is hardening rather than an observed fault.
Testing: all three compile clean on v143 / MSVC 14.44, Release x64. They have not been runtime-tested — I don't have HidModifierPrivate.cpp, so a local build isn't feature-equivalent to a release and wouldn't be a meaningful test. Happy to test a build if that's useful.