Fix logic inversion in FlexBuffers VerifyKey() — null terminator check#9072
Open
kakarotsec wants to merge 1 commit intogoogle:masterfrom
Open
Fix logic inversion in FlexBuffers VerifyKey() — null terminator check#9072kakarotsec wants to merge 1 commit intogoogle:masterfrom
kakarotsec wants to merge 1 commit intogoogle:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
VerifyKey() returns true on the first non-zero byte instead of checking for a null terminator. This causes VerifyBuffer() to accept FlexBuffers with non-null-terminated keys. Subsequent access to those keys via strlen()/strcmp() reads out of bounds. The condition if (*p++) should be if (!*p++) — return true when a null terminator is found, not when any non-zero byte is found. Confirmed with AddressSanitizer: heap-buffer-overflow in strlen() after VerifyBuffer() returns true on a corrupted buffer.
2c64b95 to
76812fd
Compare
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.
Problem
VerifyKey()in include/flatbuffers/flexbuffers.h (line 1979) has a logic inversion. It returnstrueon the first non-zero byte instead of checking for a null terminator:Since every valid key starts with a non-zero ASCII character, this function effectively always returns
trueregardless of whether the key has a null terminator within the buffer.Impact
Buffers with non-null-terminated keys pass
VerifyBuffer(). When the application then accesses those keys,strlen()andstrcmp()read past the buffer boundary.ASan output:
Fix
Return
truewhen a zero byte (null terminator) is found. Returnfalsewhen the end of buffer is reached without finding one.Verification
After the fix,
VerifyBuffer()correctly rejects corrupted buffers: