Skip to content

Commit

Permalink
matcher: fix UB bug caused by dereferencing a bad optional (#14271)
Browse files Browse the repository at this point in the history
Signed-off-by: Snow Pettersen <snowp@lyft.com>
  • Loading branch information
snowp authored Dec 7, 2020
1 parent d382fa6 commit ebdcf7c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion source/common/matcher/field_matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ struct FieldMatchResult {
// The result, if matching was completed.
absl::optional<bool> result_;

bool result() const { return *result_; }
// The unwrapped result. Should only be called if match_state_ == MatchComplete.
bool result() const {
ASSERT(match_state_ == MatchState::MatchComplete);
ASSERT(result_.has_value());
return *result_;
}
};

/**
Expand Down Expand Up @@ -87,6 +92,7 @@ template <class DataType> class AnyFieldMatcher : public FieldMatcher<DataType>

if (result.match_state_ == MatchState::UnableToMatch) {
unable_to_match_some_matchers = true;
continue;
}

if (result.result()) {
Expand Down

0 comments on commit ebdcf7c

Please sign in to comment.