Skip to content

Commit fb56d37

Browse files
jnewberyjonatack
authored andcommitted
p2p: ensure inv is GenMsgTx before ToGenTxid in inv processing
and otherwise log that an unknown INV type was received. In INV processing, when handling transaction type inv messages, ToGenTxid() expects that we constructed the CInv ourselves or that we verified that it is for a transaction type CInv. Therefore, change this `else` branch into an `else if (inv.GenMsgTx())` to make this safer and log any INVs that fall through.
1 parent aa36213 commit fb56d37

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/net_processing.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2672,7 +2672,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
26722672
// then fetch the blocks we need to catch up.
26732673
best_block = &inv.hash;
26742674
}
2675-
} else {
2675+
} else if (inv.IsGenTxMsg()) {
26762676
const GenTxid gtxid = ToGenTxid(inv);
26772677
const bool fAlreadyHave = AlreadyHaveTx(gtxid, mempool);
26782678
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
@@ -2685,6 +2685,8 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
26852685
} else if (!fAlreadyHave && !m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
26862686
RequestTx(State(pfrom.GetId()), gtxid, current_time);
26872687
}
2688+
} else {
2689+
LogPrint(BCLog::NET, "Unknown inv type \"%s\" received from peer=%d\n", inv.ToString(), pfrom.GetId());
26882690
}
26892691
}
26902692

0 commit comments

Comments
 (0)