Fix FlexBuffers VerifyKey() inverted null-terminator check#9019
Fix FlexBuffers VerifyKey() inverted null-terminator check#9019Sebasteuo 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.
|
Hi @dbaileychess, just a gentle ping on this PR. This is a one-character fix for an inverted boolean condition in ASan-confirmed crash stack: Would appreciate a review when you have a moment. Happy to add a regression Thanks! |
|
@dbaileychess added the regression test to tests/flexbuffers_test.cpp as suggested. FlexBuffersVerifyKeyOOBTest() constructs a malformed FBT_KEY buffer without null terminator and asserts VerifyBuffer() returns false. All tests pass. Ready for review. |
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.