diff options
author | Derek Bailey <derekbailey@google.com> | 2023-05-02 23:50:20 -0700 |
---|---|---|
committer | Derek Bailey <derekbailey@google.com> | 2023-05-03 00:14:27 -0700 |
commit | 75143f836b7fae6257b455c2072548d9c34e615d (patch) | |
tree | 36a933aee2fb407f7a5d702af7581ea4591f8b37 | |
parent | fb4f6fb894804fee2160ab0085e828c7d8300b80 (diff) | |
download | flatbuffers-75143f836b7fae6257b455c2072548d9c34e615d.tar.gz flatbuffers-75143f836b7fae6257b455c2072548d9c34e615d.tar.bz2 flatbuffers-75143f836b7fae6257b455c2072548d9c34e615d.zip |
fix possible null dereference for nested_root accessor
4 files changed, 36 insertions, 12 deletions
diff --git a/tests/cpp17/generated_cpp17/monster_test_generated.h b/tests/cpp17/generated_cpp17/monster_test_generated.h index 8433c094..1d593359 100644 --- a/tests/cpp17/generated_cpp17/monster_test_generated.h +++ b/tests/cpp17/generated_cpp17/monster_test_generated.h @@ -1500,7 +1500,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER); } const MyGame::Example::Monster *testnestedflatbuffer_nested_root() const { - return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testnestedflatbuffer()->Data()); + const auto _f = testnestedflatbuffer(); + return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data()) + : nullptr; } const MyGame::Example::Stat *testempty() const { return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY); @@ -1605,7 +1607,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX); } flexbuffers::Reference flex_flexbuffer_root() const { - return flexbuffers::GetRoot(flex()->Data(), flex()->size()); + const auto _f = flex(); + return _f ? flexbuffers::GetRoot(_f->Data(), _f->size()) + : flexbuffers::Reference(); } const ::flatbuffers::Vector<const MyGame::Example::Test *> *test5() const { return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5); @@ -1735,7 +1739,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER); } const MyGame::Example::Monster *testrequirednestedflatbuffer_nested_root() const { - return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testrequirednestedflatbuffer()->Data()); + const auto _f = testrequirednestedflatbuffer(); + return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data()) + : nullptr; } const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *scalar_key_sorted_tables() const { return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES); diff --git a/tests/monster_test_suffix/ext_only/monster_test_generated.hpp b/tests/monster_test_suffix/ext_only/monster_test_generated.hpp index eebb0c6f..d11788e1 100644 --- a/tests/monster_test_suffix/ext_only/monster_test_generated.hpp +++ b/tests/monster_test_suffix/ext_only/monster_test_generated.hpp @@ -1487,7 +1487,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER); } const MyGame::Example::Monster *testnestedflatbuffer_nested_root() const { - return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testnestedflatbuffer()->Data()); + const auto _f = testnestedflatbuffer(); + return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data()) + : nullptr; } const MyGame::Example::Stat *testempty() const { return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY); @@ -1592,7 +1594,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX); } flexbuffers::Reference flex_flexbuffer_root() const { - return flexbuffers::GetRoot(flex()->Data(), flex()->size()); + const auto _f = flex(); + return _f ? flexbuffers::GetRoot(_f->Data(), _f->size()) + : flexbuffers::Reference(); } const ::flatbuffers::Vector<const MyGame::Example::Test *> *test5() const { return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5); @@ -1722,7 +1726,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER); } const MyGame::Example::Monster *testrequirednestedflatbuffer_nested_root() const { - return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testrequirednestedflatbuffer()->Data()); + const auto _f = testrequirednestedflatbuffer(); + return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data()) + : nullptr; } const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *scalar_key_sorted_tables() const { return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES); diff --git a/tests/monster_test_suffix/filesuffix_only/monster_test_suffix.h b/tests/monster_test_suffix/filesuffix_only/monster_test_suffix.h index eebb0c6f..d11788e1 100644 --- a/tests/monster_test_suffix/filesuffix_only/monster_test_suffix.h +++ b/tests/monster_test_suffix/filesuffix_only/monster_test_suffix.h @@ -1487,7 +1487,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER); } const MyGame::Example::Monster *testnestedflatbuffer_nested_root() const { - return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testnestedflatbuffer()->Data()); + const auto _f = testnestedflatbuffer(); + return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data()) + : nullptr; } const MyGame::Example::Stat *testempty() const { return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY); @@ -1592,7 +1594,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX); } flexbuffers::Reference flex_flexbuffer_root() const { - return flexbuffers::GetRoot(flex()->Data(), flex()->size()); + const auto _f = flex(); + return _f ? flexbuffers::GetRoot(_f->Data(), _f->size()) + : flexbuffers::Reference(); } const ::flatbuffers::Vector<const MyGame::Example::Test *> *test5() const { return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5); @@ -1722,7 +1726,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER); } const MyGame::Example::Monster *testrequirednestedflatbuffer_nested_root() const { - return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testrequirednestedflatbuffer()->Data()); + const auto _f = testrequirednestedflatbuffer(); + return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data()) + : nullptr; } const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *scalar_key_sorted_tables() const { return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES); diff --git a/tests/monster_test_suffix/monster_test_suffix.hpp b/tests/monster_test_suffix/monster_test_suffix.hpp index eebb0c6f..d11788e1 100644 --- a/tests/monster_test_suffix/monster_test_suffix.hpp +++ b/tests/monster_test_suffix/monster_test_suffix.hpp @@ -1487,7 +1487,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTNESTEDFLATBUFFER); } const MyGame::Example::Monster *testnestedflatbuffer_nested_root() const { - return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testnestedflatbuffer()->Data()); + const auto _f = testnestedflatbuffer(); + return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data()) + : nullptr; } const MyGame::Example::Stat *testempty() const { return GetPointer<const MyGame::Example::Stat *>(VT_TESTEMPTY); @@ -1592,7 +1594,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_FLEX); } flexbuffers::Reference flex_flexbuffer_root() const { - return flexbuffers::GetRoot(flex()->Data(), flex()->size()); + const auto _f = flex(); + return _f ? flexbuffers::GetRoot(_f->Data(), _f->size()) + : flexbuffers::Reference(); } const ::flatbuffers::Vector<const MyGame::Example::Test *> *test5() const { return GetPointer<const ::flatbuffers::Vector<const MyGame::Example::Test *> *>(VT_TEST5); @@ -1722,7 +1726,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_TESTREQUIREDNESTEDFLATBUFFER); } const MyGame::Example::Monster *testrequirednestedflatbuffer_nested_root() const { - return ::flatbuffers::GetRoot<MyGame::Example::Monster>(testrequirednestedflatbuffer()->Data()); + const auto _f = testrequirednestedflatbuffer(); + return _f ? ::flatbuffers::GetRoot<MyGame::Example::Monster>(_f->Data()) + : nullptr; } const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *scalar_key_sorted_tables() const { return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Example::Stat>> *>(VT_SCALAR_KEY_SORTED_TABLES); |