sanitize lowest slots (#9747)
This commit is contained in:
parent
c11abf88b7
commit
193dbb1794
|
@ -87,7 +87,12 @@ impl Sanitize for CrdsData {
|
||||||
}
|
}
|
||||||
val.sanitize()
|
val.sanitize()
|
||||||
}
|
}
|
||||||
CrdsData::LowestSlot(_, val) => val.sanitize(),
|
CrdsData::LowestSlot(ix, val) => {
|
||||||
|
if *ix as usize >= 1 {
|
||||||
|
return Err(SanitizeError::ValueOutOfRange);
|
||||||
|
}
|
||||||
|
val.sanitize()
|
||||||
|
}
|
||||||
CrdsData::SnapshotHashes(val) => val.sanitize(),
|
CrdsData::SnapshotHashes(val) => val.sanitize(),
|
||||||
CrdsData::AccountsHashes(val) => val.sanitize(),
|
CrdsData::AccountsHashes(val) => val.sanitize(),
|
||||||
CrdsData::EpochSlots(ix, val) => {
|
CrdsData::EpochSlots(ix, val) => {
|
||||||
|
@ -156,10 +161,19 @@ impl LowestSlot {
|
||||||
impl Sanitize for LowestSlot {
|
impl Sanitize for LowestSlot {
|
||||||
fn sanitize(&self) -> Result<(), SanitizeError> {
|
fn sanitize(&self) -> Result<(), SanitizeError> {
|
||||||
if self.wallclock >= MAX_WALLCLOCK {
|
if self.wallclock >= MAX_WALLCLOCK {
|
||||||
return Err(SanitizeError::Failed);
|
return Err(SanitizeError::ValueOutOfRange);
|
||||||
}
|
}
|
||||||
if self.lowest >= MAX_SLOT {
|
if self.lowest >= MAX_SLOT {
|
||||||
return Err(SanitizeError::Failed);
|
return Err(SanitizeError::ValueOutOfRange);
|
||||||
|
}
|
||||||
|
if self.root != 0 {
|
||||||
|
return Err(SanitizeError::InvalidValue);
|
||||||
|
}
|
||||||
|
if !self.slots.is_empty() {
|
||||||
|
return Err(SanitizeError::InvalidValue);
|
||||||
|
}
|
||||||
|
if !self.stash.is_empty() {
|
||||||
|
return Err(SanitizeError::InvalidValue);
|
||||||
}
|
}
|
||||||
self.from.sanitize()
|
self.from.sanitize()
|
||||||
}
|
}
|
||||||
|
@ -421,6 +435,32 @@ mod test {
|
||||||
assert_eq!(v.label(), CrdsValueLabel::LowestSlot(key));
|
assert_eq!(v.label(), CrdsValueLabel::LowestSlot(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_lowest_slot_sanitize() {
|
||||||
|
let ls = LowestSlot::new(Pubkey::default(), 0, 0);
|
||||||
|
let v = CrdsValue::new_unsigned(CrdsData::LowestSlot(0, ls.clone()));
|
||||||
|
assert_eq!(v.sanitize(), Ok(()));
|
||||||
|
|
||||||
|
let mut o = ls.clone();
|
||||||
|
o.root = 1;
|
||||||
|
let v = CrdsValue::new_unsigned(CrdsData::LowestSlot(0, o.clone()));
|
||||||
|
assert_eq!(v.sanitize(), Err(SanitizeError::InvalidValue));
|
||||||
|
|
||||||
|
let o = ls.clone();
|
||||||
|
let v = CrdsValue::new_unsigned(CrdsData::LowestSlot(1, o.clone()));
|
||||||
|
assert_eq!(v.sanitize(), Err(SanitizeError::ValueOutOfRange));
|
||||||
|
|
||||||
|
let mut o = ls.clone();
|
||||||
|
o.slots.insert(1);
|
||||||
|
let v = CrdsValue::new_unsigned(CrdsData::LowestSlot(0, o.clone()));
|
||||||
|
assert_eq!(v.sanitize(), Err(SanitizeError::InvalidValue));
|
||||||
|
|
||||||
|
let mut o = ls.clone();
|
||||||
|
o.stash.push(deprecated::EpochIncompleteSlots::default());
|
||||||
|
let v = CrdsValue::new_unsigned(CrdsData::LowestSlot(0, o.clone()));
|
||||||
|
assert_eq!(v.sanitize(), Err(SanitizeError::InvalidValue));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_signature() {
|
fn test_signature() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
|
|
|
@ -3,6 +3,7 @@ pub enum SanitizeError {
|
||||||
Failed,
|
Failed,
|
||||||
IndexOutOfBounds,
|
IndexOutOfBounds,
|
||||||
ValueOutOfRange,
|
ValueOutOfRange,
|
||||||
|
InvalidValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Sanitize {
|
pub trait Sanitize {
|
||||||
|
|
Loading…
Reference in New Issue