Skip to content

Commit

Permalink
fix(zpool): Integer overflow in zpool parser.
Browse files Browse the repository at this point in the history
Closes issue #88
  • Loading branch information
andoriyu committed Aug 25, 2019
1 parent 625cedb commit 36fc071
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Binary file not shown.
9 changes: 9 additions & 0 deletions src/parsers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,13 @@ errors: No known data errors

assert_eq!(&topo, &zpool);
}

#[test]
fn test_zpool_int_overflow() {
let stdout = include_str!("fixtures/SIGABRT.PID.84191.TIME.2019-08-21.20.04.09.fuzz");
let mut pairs =
StdoutParser::parse(Rule::zpools, stdout).unwrap_or_else(|e| panic!("{}", e));
let pair = pairs.next().unwrap();
let zpool = Zpool::from_pest_pair(pair);
}
}
6 changes: 3 additions & 3 deletions src/zpool/description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ fn get_error_statistics_from_pair(pair: Pair<'_, Rule>) -> ErrorStatistics {
debug_assert_eq!(Rule::error_statistics, pair.as_rule());
let mut inner = pair.into_inner();
ErrorStatistics {
read: inner.next().unwrap().as_span().as_str().parse().unwrap(),
write: inner.next().unwrap().as_span().as_str().parse().unwrap(),
checksum: inner.next().unwrap().as_span().as_str().parse().unwrap(),
read: inner.next().unwrap().as_span().as_str().parse().unwrap_or(std::u64::MAX),
write: inner.next().unwrap().as_span().as_str().parse().unwrap_or(std::u64::MAX),
checksum: inner.next().unwrap().as_span().as_str().parse().unwrap_or(std::u64::MAX),
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/zpool/vdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ use std::{default::Default,
use crate::zpool::{Health, Reason, ZpoolError};

/// Error statistics.
///
/// NOTE: Due to imperfections of our world number of errors limited to [`std::u64::MAX`](https://doc.rust-lang.org/std/u64/constant.MAX.html).
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct ErrorStatistics {
/// I/O errors that occurred while issuing a read request
pub read: u64,
/// I/O errors that occurred while issuing a write request
pub write: u64,
/// Checksum errors, meaning that the device returned corrupted data as the
/// Checksum errors, meaning the device returned corrupted data as the
/// result of a read request
pub checksum: u64,
}
Expand Down

0 comments on commit 36fc071

Please sign in to comment.