* checks that prune-messages have the same inner/outer pubkey (#15352)
(cherry picked from commit 076c20f1ca
)
# Conflicts:
# core/src/cluster_info.rs
* removes backport merge conflicts
Co-authored-by: behzad nouri <behzadnouri@gmail.com>
This commit is contained in:
@ -331,7 +331,7 @@ impl fmt::Debug for Locality {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize, AbiExample)]
|
||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, AbiExample)]
|
||||
pub struct PruneData {
|
||||
/// Pubkey of the node that sent this prune data
|
||||
pub pubkey: Pubkey,
|
||||
@ -431,6 +431,8 @@ enum Protocol {
|
||||
PullRequest(CrdsFilter, CrdsValue),
|
||||
PullResponse(Pubkey, Vec<CrdsValue>),
|
||||
PushMessage(Pubkey, Vec<CrdsValue>),
|
||||
// TODO: Remove the redundant outer pubkey here,
|
||||
// and use the inner PruneData.pubkey instead.
|
||||
PruneMessage(Pubkey, PruneData),
|
||||
PingMessage(Ping),
|
||||
PongMessage(Pong),
|
||||
@ -514,7 +516,13 @@ impl Sanitize for Protocol {
|
||||
}
|
||||
Protocol::PullResponse(_, val) => val.sanitize(),
|
||||
Protocol::PushMessage(_, val) => val.sanitize(),
|
||||
Protocol::PruneMessage(_, val) => val.sanitize(),
|
||||
Protocol::PruneMessage(from, val) => {
|
||||
if *from != val.pubkey {
|
||||
Err(SanitizeError::InvalidValue)
|
||||
} else {
|
||||
val.sanitize()
|
||||
}
|
||||
}
|
||||
Protocol::PingMessage(ping) => ping.sanitize(),
|
||||
Protocol::PongMessage(pong) => pong.sanitize(),
|
||||
}
|
||||
@ -4135,6 +4143,23 @@ mod tests {
|
||||
assert_eq!(msg.sanitize(), Err(SanitizeError::ValueOutOfBounds));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_protocol_prune_message_sanitize() {
|
||||
let keypair = Keypair::new();
|
||||
let mut prune_data = PruneData {
|
||||
pubkey: keypair.pubkey(),
|
||||
prunes: vec![],
|
||||
signature: Signature::default(),
|
||||
destination: Pubkey::new_unique(),
|
||||
wallclock: timestamp(),
|
||||
};
|
||||
prune_data.sign(&keypair);
|
||||
let prune_message = Protocol::PruneMessage(keypair.pubkey(), prune_data.clone());
|
||||
assert_eq!(prune_message.sanitize(), Ok(()));
|
||||
let prune_message = Protocol::PruneMessage(Pubkey::new_unique(), prune_data);
|
||||
assert_eq!(prune_message.sanitize(), Err(SanitizeError::InvalidValue));
|
||||
}
|
||||
|
||||
// computes the maximum size for pull request blooms
|
||||
fn max_bloom_size() -> usize {
|
||||
let filter_size = serialized_size(&CrdsFilter::default())
|
||||
|
Reference in New Issue
Block a user