Repository navigation
Conversation
…skip in upb_Message_Next
upb_DefPool_FindExtensionByMiniTable() declares an uninitialized `upb_value v`,
calls upb_inttable_lookup(&s->exts, (uintptr_t)ext, &v), asserts `ok`, and
unconditionally returns upb_value_getconstptr(v). When `ext` is not registered
in `s`:
- In debug builds, UPB_ASSERT(ok) aborts.
- In release (-DNDEBUG) builds, `v` is never written and the function returns
an uninitialized stack value cast to `const upb_FieldDef*`.
This directly breaks the documented contract of upb_Message_Next() in
upb/reflection/message.h ("If the given symtab returns extensions that don't
match what is in this message, those extensions will be skipped"), causing
wild-pointer dereferences (SIGSEGV) in callers such as upb_Message_Next(),
upb_TextEncode(), upb_JsonEncode(), upb_Message_DiscardUnknown(), and
upb_util_HasUnsetRequired().
Return NULL from upb_DefPool_FindExtensionByMiniTable() when the lookup misses,
and skip entries where upb_DefPool_FindExtensionByMiniTable() returns NULL in
upb_Message_Next().
This branch has not been deployed
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.
Summary
Fixes an uninitialized stack pointer return in
upb_DefPool_FindExtensionByMiniTable()(upb/reflection/def_pool.c) and a missingNULLcheck inupb_Message_Next()(upb/reflection/message.c).Root Cause
upb_DefPool_FindExtensionByMiniTable()(upb/reflection/def_pool.c:622-628) declares an uninitializedupb_value v, callsupb_inttable_lookup(&s->exts, (uintptr_t)ext, &v), assertsok, and unconditionally returnsupb_value_getconstptr(v). Whenextis not registered ins:UPB_ASSERT(ok).-DNDEBUG) builds return an uninitialized stack value cast toconst upb_FieldDef*.upb_Message_Next()(upb/reflection/message.c:180-191) is explicitly documented inupb/reflection/message.h:70-72to skip extensions that do not match the providedext_pool:Fix
NULLfromupb_DefPool_FindExtensionByMiniTable()whenupb_inttable_lookup()misses.upb_Message_Next(), check the returnedconst upb_FieldDef*andcontinuepast extensions missing fromext_pool.Testing
MessageTest.MessageNextSkipsExtensionsMissingFromExtPoolinupb/message/test.cccovering directupb_DefPool_FindExtensionByMiniTable(),upb_Message_Next(),upb_JsonEncode(), andupb_Message_DiscardUnknown().-DNDEBUG) and Debug builds as well as-std=c99 -Wall -Wextra -Werror.