Fix off-by-one overflow in windows_get_registry_files()#1932
Open
saddamr3e wants to merge 1 commit into
Open
Conversation
|
Author saddamr3e not on autobuild list. Waiting for curator authorization before starting CI build. |
1 similar comment
|
Author saddamr3e not on autobuild list. Waiting for curator authorization before starting CI build. |
|
|
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.
Fix an off-by-one heap buffer overflow in
windows_get_registry_files()when accumulating manifest paths enumerated from Windows registry locations.The growth check reserved space for the new path and terminating null byte, but failed to account for the additional
PATH_SEPARATORinserted before appended entries. Under specific path-length combinations, this allowed a one-byte write past the end of the allocated buffer.This change:
Corrects the capacity check to reserve space for:
PATH_SEPARATORUses the actual destination capacity when calling
snprintf()Bounds appended writes using the remaining buffer size
Adds a regression test that reproduces the boundary condition which previously triggered the overflow
Root Cause
When appending a new registry entry, the code checked:
but the subsequent write emitted:
which requires an additional byte for the separator.
As a result, if:
the buffer would not be grown and the terminating null byte would be written one byte beyond the allocation.
Testing
Added
RegistryManifestParsing.AppendAtBufferBoundaryDoesNotOverflow.The test constructs registry value names whose combined lengths place the final append exactly at the original 4096-byte allocation boundary. Prior to this fix, the test triggers a one-byte heap overflow (detectable under ASAN). After the fix, the buffer is correctly expanded and instance creation completes successfully.
Impact
Prevents a heap-based off-by-one overflow during Windows registry manifest enumeration and improves the robustness of buffer-bound calculations in this code path.