Skip to content

Commit

Permalink
Check access to included schema list
Browse files Browse the repository at this point in the history
Summary: Avoid out-of-bounds access when a dependency has schema disabled.

Reviewed By: createdbysk

Differential Revision: D70001932

fbshipit-source-id: 33f5ef434416a5fd76571fdbf618816da8bac339
  • Loading branch information
iahs authored and facebook-github-bot committed Feb 22, 2025
1 parent ba731b1 commit f20ed2e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion thrift/lib/cpp2/gen/module_constants_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ ::std::string_view readSchema(::std::string_view (*access)()) {
::std::string_view readSchemaInclude(
::folly::Range<const ::std::string_view*> (*access)(),
::std::size_t index) {
return access()[index];
auto range = access();
return index < range.size() ? range[index] : "";
}

} // namespace apache::thrift::detail::mc
4 changes: 2 additions & 2 deletions thrift/test/SchemaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TEST(SchemaTest, linked) {
TEST(SchemaTest, static_schema) {
auto static_schema = SchemaRegistry::mergeSchemas(
facebook::thrift::test::schema::schema_constants::
_fbthrift_schema_fba4d3dcfb7c979a_includes());
_fbthrift_schema_542ebcbee39d65d1_includes());
const type::Program* static_program = nullptr;
for (const auto& program : *static_schema.programs()) {
if (program.path() == "thrift/test/schema.thrift") {
Expand All @@ -115,7 +115,7 @@ TEST(SchemaTest, static_schema) {

TEST(SchemaTest, merged_schema_add_after_access) {
auto data = facebook::thrift::test::schema::schema_constants::
_fbthrift_schema_fba4d3dcfb7c979a();
_fbthrift_schema_542ebcbee39d65d1();

BaseSchemaRegistry base;
SchemaRegistry registry(base);
Expand Down
1 change: 1 addition & 0 deletions thrift/test/schema.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

include "thrift/annotation/scope.thrift"
include "thrift/annotation/cpp.thrift"
include "thrift/lib/thrift/patch.thrift" // @nolint used to test depending on this file

package "facebook.com/thrift/test/schema"

Expand Down

0 comments on commit f20ed2e

Please sign in to comment.