Fix FlexBuffers VerifyKey() inverted null-terminator check#9019
Open
Sebasteuo wants to merge 1 commit intogoogle:masterfrom
Open
Fix FlexBuffers VerifyKey() inverted null-terminator check#9019Sebasteuo wants to merge 1 commit intogoogle:masterfrom
Sebasteuo wants to merge 1 commit intogoogle:masterfrom
Conversation
VerifyKey() incorrectly returned true upon encountering a non-null byte instead of verifying that a null terminator exists within the buffer bounds. This caused the verifier to accept buffers with non-null-terminated keys, leading to out-of-bounds reads via strlen() in AsString(), AsKey(), and ToString(). Found via fuzzing with AddressSanitizer.
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 FlexBuffers VerifyKey() inverted null-terminator check
VerifyKey()incorrectly returnedtrueupon encountering a non-null byte instead of verifying that a null terminator exists within the buffer bounds.Bug
The condition
if (*p++) return true;returns true on the first non-null byte, meaning any key with at least one non-null byte passes verification regardless of whether a null terminator exists within the buffer.Impact
After verification, calls to
AsString(),AsKey(), orToString()on aFBT_KEYreference invokestrlen()which reads past the buffer boundary (heap/stack OOB read).Fix
Negate the condition to check for the null terminator:
Reproduction
Compile with:
clang++ -fsanitize=address -I include poc.cc src/util.cppFound via fuzzing with AddressSanitizer.