Repository navigation
Hardening: add null guards, bounds checks, and optional safety to IDL generators and schema emitters - #9367
Closed
anagnorisis2peripeteia wants to merge 1 commit into
Conversation
… generators and schema emitters
Author
|
Closing this pull request. These checks guard states a correct parse does not produce, or they treat a missing file_saver as a successful generate. FlatBuffers does not put that check in the generators. A schema problem is a parser error. A caller mistake is FLATBUFFERS_ASSERT. An untrusted buffer is checked in the verifier. See the C++ guide section "Access of untrusted buffers" and the review on #8990. |
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.
Description
This PR defensively hardens IDL code generators and schema emitters against null dereferences and iterator/container bounds issues:
src/idl_gen_fbs.cpp:GenTypeagainst nullstruct_defor nulldefined_namespace.used_proto_ids.size() >= 2inHasTwiceUsedIdandHasGapInProtoIdbefore callingstd::next(std::begin(...))to eliminate undefined iterator advancing on small or empty vectors.FieldDef*entries inHasFieldWithId,HasNonPositiveFieldId,HasFieldIdFromReservedIds,ExtractProtobufIds, andMapProtoIdsToFieldsId.GenerateFBS: bounds-checksns.from_table <= ns.components.size()before performing reverse component indexing and iterator subtractions; skips null namespace/enum/struct pointers; guardsenum_def.defined_namespaceandstruct_def.defined_namespace; guardsparser.opts.file_saverbefore invokingSaveFile.src/idl_gen_binary.cpp:parser.opts.file_saverinGenerateBinaryfor both flexbuffers and standard flatbuffers.parser.root_struct_def_before accessing itsfilemember inBinaryMakeRule.src/idl_gen_cpp.cpp:generate_bfbs_embedandgenerateagainst nullparser_.opts.file_saver.src/idl_gen_text.cpp:parser.opts.file_saverinGenTextFilebefore callingSaveFile, returning a failure string rather than dereferencing null.tests/test.cpp:IdlGeneratorsSafetyTestvalidating safe handling of nullfile_saverinGenTextFileandNewFBSCodeGenerator.