[thin/cache (rust)] Validate superblock checksum

This commit is contained in:
Ming-Hung Tsai 2021-08-27 11:17:27 +08:00
parent 8a822cebec
commit 71d47ef58b
2 changed files with 10 additions and 2 deletions

View File

@ -134,7 +134,11 @@ fn unpack(data: &[u8]) -> IResult<&[u8], Superblock> {
pub fn read_superblock(engine: &dyn IoEngine, loc: u64) -> Result<Superblock> {
let b = engine.read(loc)?;
if let Ok((_, sb)) = unpack(&b.get_data()) {
if metadata_block_type(b.get_data()) != BT::CACHE_SUPERBLOCK {
return Err(anyhow!("bad checksum in superblock"));
}
if let Ok((_, sb)) = unpack(b.get_data()) {
Ok(sb)
} else {
Err(anyhow!("couldn't unpack superblock"))

View File

@ -89,7 +89,11 @@ fn unpack(data: &[u8]) -> IResult<&[u8], Superblock> {
pub fn read_superblock(engine: &dyn IoEngine, loc: u64) -> Result<Superblock> {
let b = engine.read(loc)?;
if let Ok((_, sb)) = unpack(&b.get_data()) {
if metadata_block_type(b.get_data()) != BT::THIN_SUPERBLOCK {
return Err(anyhow!("bad checksum in superblock"));
}
if let Ok((_, sb)) = unpack(b.get_data()) {
Ok(sb)
} else {
Err(anyhow!("couldn't unpack superblock"))