From f63f74054599a3da27f5487d5efbcb19b4c8f20b Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 9 Oct 2020 17:40:51 -0700 Subject: [PATCH] agent: fix errorneous parsing for guest block size We were assuming base 10 string before, when the block size from sysfs is actually a hex string. Let's fix that. Fixes: #908 Signed-off-by: Eric Ernst --- src/agent/src/rpc.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index ed71402742..3fab2835ca 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -1407,7 +1407,13 @@ fn get_memory_info(block_size: bool, hotplug: bool) -> Result<(u64, bool)> { return Err(anyhow!("Invalid block size")); } - size = v.trim().parse::()?; + size = match u64::from_str_radix(v.trim(), 16) { + Ok(h) => h, + Err(_) => { + warn!(sl!(), "failed to parse the str {} to hex", size); + return Err(anyhow!("Invalid block size")); + } + }; } Err(e) => { info!(sl!(), "memory block size error: {:?}", e.kind());