summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2022-04-27 21:04:05 +0000
committerAlyssa Ross <hi@alyssa.is>2022-04-27 21:11:11 +0000
commit9226197f1e9b9f17caf501b2a80b740b2da4af54 (patch)
tree24d6aae796687b74ed984cc633920fa474b96fdb
parentab9d7bf6d7e7b4cdd77933d57992aad64be3c4f6 (diff)
downloadspectrum-9226197f1e9b9f17caf501b2a80b740b2da4af54.tar
spectrum-9226197f1e9b9f17caf501b2a80b740b2da4af54.tar.gz
spectrum-9226197f1e9b9f17caf501b2a80b740b2da4af54.tar.bz2
spectrum-9226197f1e9b9f17caf501b2a80b740b2da4af54.tar.lz
spectrum-9226197f1e9b9f17caf501b2a80b740b2da4af54.tar.xz
spectrum-9226197f1e9b9f17caf501b2a80b740b2da4af54.tar.zst
spectrum-9226197f1e9b9f17caf501b2a80b740b2da4af54.zip
host/start-vm: don't allow VM name to contain ','
cloud-hypervisor would misintepret these if they were passed on its
command line.
-rw-r--r--host/start-vm/start-vm.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/host/start-vm/start-vm.rs b/host/start-vm/start-vm.rs
index 484fd60..ab856ea 100644
--- a/host/start-vm/start-vm.rs
+++ b/host/start-vm/start-vm.rs
@@ -21,6 +21,10 @@ fn vm_command(dir: PathBuf) -> Result<Command, String> {
         .file_name()
         .ok_or_else(|| "directory has no name".to_string())?;
 
+    if vm_name.as_bytes().contains(&b',') {
+        return Err(format!("VM name may not contain a comma: {:?}", vm_name));
+    }
+
     let mut command = Command::new("s6-notifyoncheck");
     command.args(&["-dc", "test -S env/cloud-hypervisor.sock"]);
     command.arg("cloud-hypervisor");
@@ -110,3 +114,13 @@ fn main() {
     eprintln!("{}: {}", argv0, run());
     exit(1);
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn test_vm_name_comma() {
+        assert!(vm_command("/v,m".into()).unwrap_err().contains("comma"));
+    }
+}