From c76c2dae56042b7614c2d0c915958adc59082dfd Mon Sep 17 00:00:00 2001 From: Nicholas Hollingum Date: Fri, 18 Sep 2020 15:53:16 +1000 Subject: [PATCH] crosvm: Support "=" in --serial args The --serial option does not support args that have the '=' character (or the ',' character for that matter, but we dont mind so much there). This became a problem after crreev.com/c/2386885 made all encoded VM names include padding, as the padding charcter '=' caused serial paths like "foo=.log" to be interpreted as "foo". This was not noticed because: - Logging is not covered in automated testing. - My vm name was "brl" in manual testing, which does not require padding when b64 encoded. BUG=b:168859379 TEST=vmc start termina; grep maitred /run/daemon.../log/dGVybWluYQ==.log Change-Id: I07ffd1c76abab1866a8fb54763605c0ef8733776 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2417797 Tested-by: kokoro Tested-by: Nic Hollingum Reviewed-by: Nicholas Verne Reviewed-by: Dylan Reid Commit-Queue: Fergus Dall --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1b6021d7d6..f4d1c46d18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -401,7 +401,7 @@ fn parse_serial_options(s: &str) -> argument::Result { let opts = s .split(',') - .map(|frag| frag.split('=')) + .map(|frag| frag.splitn(2, '=')) .map(|mut kv| (kv.next().unwrap_or(""), kv.next().unwrap_or(""))); for (k, v) in opts { @@ -2194,6 +2194,13 @@ mod tests { parse_serial_options("type=syslog").expect("parse should have succeded"); } + #[test] + fn parse_serial_equals_in_value() { + let parsed = parse_serial_options("type=syslog,path=foo=bar==.log") + .expect("parse should have succeded"); + assert_eq!(parsed.path, Some(PathBuf::from("foo=bar==.log"))); + } + #[test] fn parse_serial_invalid_type() { parse_serial_options("type=wormhole,num=1").expect_err("parse should have failed");