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| { if parts.len() == 2 {
let parts = r.split('-').collect::<Vec<&str>>(); let start =
if parts.len() == 2 { GuestAddr::from_str_radix(parts[0].trim_start_matches("0x"), 16).map_err(|e| {
let start = GuestAddr::from_str_radix(parts[0].trim_start_matches("0x"), 16) Error::illegal_argument(format!("Invalid start address: {} ({e:})", parts[0]))
.map_err(|e| { })?;
Error::illegal_argument(format!( let end =
"Invalid start address: {} ({e:})", GuestAddr::from_str_radix(parts[1].trim_start_matches("0x"), 16).map_err(|e| {
parts[0] Error::illegal_argument(format!("Invalid end address: {} ({e:})", parts[1]))
)) })?;
})?; Ok(Range { start, end })
let end = GuestAddr::from_str_radix(parts[1].trim_start_matches("0x"), 16) } else {
.map_err(|e| { Err(Error::illegal_argument(format!(
Error::illegal_argument(format!( "Invalid range provided: {src:}"
"Invalid end address: {} ({e:})", )))
parts[1] }
))
})?;
Ok(Range { start, end })
} else {
Err(Error::illegal_argument(format!(
"Invalid range provided: {r:}"
)))
}
})
.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 {