Skip to content

Nested FromConfable schemas in a Map schema leads to segfault #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cassava opened this issue Nov 13, 2023 · 1 comment · Fixed by #202
Closed

Nested FromConfable schemas in a Map schema leads to segfault #186

cassava opened this issue Nov 13, 2023 · 1 comment · Fixed by #202
Assignees
Labels
bug Something isn't working c-fable Domain is the fable library
Milestone

Comments

@cassava
Copy link
Contributor

cassava commented Nov 13, 2023

Minimum test:

template <typename T>
struct Nested : public fable::Confable {
  T value{}; // NOLINT

 public:
  CONFABLE_SCHEMA(Nested<T>) {
    return fable::Schema{
      { "v", fable::Schema(&value, "nested value") },
    };
  }
};

template <typename T>
struct MapOfSomething : public fable::Confable {
  std::map<std::string, T> values; // NOLINT

 public:
  CONFABLE_SCHEMA(MapOfSomething<T>) {
    return fable::Schema{
        {"values", fable::Schema(&values, "")},
    };
  }
};

TEST(fable_schema_map, validate_map_of_nested_3x) {
  MapOfSomething<Nested<Nested<Nested<double>>>> wrapper;

  fable::assert_validate(wrapper, R"({
    "values": {
      "a": {
        "v": { "v": { "v": 1.0 } }
      }
    }
  })");
}

Leads to output:

The following tests FAILED:
	 33 - fable_schema_map.validate_map_of_nested_3x (SEGFAULT)

With valgrind execution giving the following information:

[ RUN      ] fable_schema_map.validate_map_of_nested_3x
==354081== Use of uninitialised value of size 8
==354081==    at 0x1E69F5: fable::schema::FromConfable<(anonymous namespace)::Nested<double>, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:68)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x1E92B9: fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> >, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:66)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x1EAB9B: fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:66)
==354081==    by 0x1EA0CC: fable::schema::Map<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, 0> >::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (map.hpp:141)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
==354081==  Uninitialised value was created by a stack allocation
==354081==    at 0x1E9C20: fable::schema::Map<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, 0> >::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (map.hpp:111)
==354081==
==354081== Invalid read of size 8
==354081==    at 0x1E69F5: fable::schema::FromConfable<(anonymous namespace)::Nested<double>, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:68)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x1E92B9: fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> >, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:66)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x1EAB9B: fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:66)
==354081==    by 0x1EA0CC: fable::schema::Map<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, 0> >::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (map.hpp:141)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
==354081==  Address 0x1ffeff0050 is not stack'd, malloc'd or (recently) free'd
==354081==
==354081==
==354081== Process terminating with default action of signal 11 (SIGSEGV)
==354081==  Access not within mapped region at address 0x1FFEFF0050
==354081==    at 0x1E69F5: fable::schema::FromConfable<(anonymous namespace)::Nested<double>, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:68)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x1E92B9: fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> >, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:66)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x1EAB9B: fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, 0>::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (confable.hpp:66)
==354081==    by 0x1EA0CC: fable::schema::Map<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, fable::schema::FromConfable<(anonymous namespace)::Nested<(anonymous namespace)::Nested<(anonymous namespace)::Nested<double> > >, 0> >::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (map.hpp:141)
==354081==    by 0x1875BE: fable::schema::Box::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (interface.hpp:377)
==354081==    by 0x2F740B: fable::schema::Struct::validate(fable::Conf const&, std::optional<fable::SchemaError>&) const (struct.cpp:125)
@cassava cassava added c-fable Domain is the fable library bug Something isn't working labels Nov 13, 2023
@cassava cassava self-assigned this Nov 13, 2023
@cassava
Copy link
Contributor Author

cassava commented Nov 13, 2023

Reproduced, tests written, issue resolved.

@cassava cassava closed this as completed Nov 13, 2023
@cassava cassava added this to the 0.21.0 milestone Dec 6, 2023
CzBalti pushed a commit to CzBalti/cloe that referenced this issue Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working c-fable Domain is the fable library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant