qemu_launcher: Fix command line parsing of ranges (#2804)

Co-authored-by: Your Name <you@example.com>
Co-authored-by: Dominik Maier <domenukk@gmail.com>
This commit is contained in:
WorksButNotTested 2025-01-03 15:04:41 +00:00 committed by GitHub
parent d39ded5b29
commit da55e70aa3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -92,33 +92,23 @@ impl FuzzerOptions {
Ok(Duration::from_millis(src.parse()?)) Ok(Duration::from_millis(src.parse()?))
} }
fn parse_ranges(src: &str) -> Result<Vec<Range<GuestAddr>>, Error> { fn parse_ranges(src: &str) -> Result<Range<GuestAddr>, Error> {
src.split(',') let parts = src.split('-').collect::<Vec<&str>>();
.map(|r| {
let parts = r.split('-').collect::<Vec<&str>>();
if parts.len() == 2 { if parts.len() == 2 {
let start = GuestAddr::from_str_radix(parts[0].trim_start_matches("0x"), 16) let start =
.map_err(|e| { GuestAddr::from_str_radix(parts[0].trim_start_matches("0x"), 16).map_err(|e| {
Error::illegal_argument(format!( Error::illegal_argument(format!("Invalid start address: {} ({e:})", parts[0]))
"Invalid start address: {} ({e:})",
parts[0]
))
})?; })?;
let end = GuestAddr::from_str_radix(parts[1].trim_start_matches("0x"), 16) let end =
.map_err(|e| { GuestAddr::from_str_radix(parts[1].trim_start_matches("0x"), 16).map_err(|e| {
Error::illegal_argument(format!( Error::illegal_argument(format!("Invalid end address: {} ({e:})", parts[1]))
"Invalid end address: {} ({e:})",
parts[1]
))
})?; })?;
Ok(Range { start, end }) Ok(Range { start, end })
} else { } else {
Err(Error::illegal_argument(format!( Err(Error::illegal_argument(format!(
"Invalid range provided: {r:}" "Invalid range provided: {src:}"
))) )))
} }
})
.collect::<Result<Vec<Range<GuestAddr>>, Error>>()
} }
pub fn is_asan_core(&self, core_id: CoreId) -> bool { pub fn is_asan_core(&self, core_id: CoreId) -> bool {