Skip to content

Commit 4ef9103

Browse files
committed
Merge pull request google#763 from AlCutter/no_crash_on_old_head
Don't crash the mirror if we see an older STH.
2 parents 4148d6f + 6c4845a commit 4ef9103

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

cpp/fetcher/remote_peer.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,18 @@ void RemotePeer::Impl::DoneGetSTH(
7474
LogVerifier::VERIFY_OK)
7575
<< "could not validate STH:\n" << new_sth->DebugString();
7676

77-
lock_guard<mutex> lock(lock_);
77+
// TODO(alcutter): Need to check STH consistency here, including for older
78+
// STHs which might come in.
7879

79-
if (sth_) {
80-
CHECK_GE(new_sth->tree_size(), sth_->tree_size());
81-
} else {
82-
CHECK_GE(new_sth->tree_size(), 0);
83-
}
80+
lock_guard<mutex> lock(lock_);
8481

85-
if (!sth_ || new_sth->timestamp() > sth_->timestamp()) {
82+
if (new_sth->tree_size() < 0) {
83+
LOG(WARNING) << "Unexpected tree size in new_sth:\n"
84+
<< new_sth->DebugString();
85+
} else if (sth_ && new_sth->tree_size() < sth_->tree_size()) {
86+
LOG(WARNING) << "Received old STH:\n" << new_sth->DebugString();
87+
} else if (!sth_ || new_sth->timestamp() > sth_->timestamp()) {
88+
// This STH is good, we'll take it.
8689
sth_ = new_sth;
8790
if (on_new_sth_) {
8891
on_new_sth_(*sth_);

0 commit comments

Comments
 (0)