(root: &Path, state_dir: &Path)
| 4211 | |
| 4212 | #[allow(clippy::result_large_err)] |
| 4213 | fn validate_sandbox_state_dir(root: &Path, state_dir: &Path) -> Result<(), Status> { |
| 4214 | let sandboxes_root = sandboxes_root_dir(root); |
| 4215 | let relative = state_dir.strip_prefix(&sandboxes_root).map_err(|_| { |
| 4216 | Status::internal(format!( |
| 4217 | "refusing to use sandbox state path outside vm state root: {}", |
| 4218 | state_dir.display() |
| 4219 | )) |
| 4220 | })?; |
| 4221 | |
| 4222 | let mut components = relative.components(); |
| 4223 | match components.next() { |
| 4224 | Some(Component::Normal(_)) => {} |
| 4225 | _ => { |
| 4226 | return Err(Status::internal(format!( |
| 4227 | "refusing to use malformed sandbox state path: {}", |
| 4228 | state_dir.display() |
| 4229 | ))); |
| 4230 | } |
| 4231 | } |
| 4232 | if components.next().is_some() { |
| 4233 | return Err(Status::internal(format!( |
| 4234 | "refusing to use nested sandbox state path: {}", |
| 4235 | state_dir.display() |
| 4236 | ))); |
| 4237 | } |
| 4238 | |
| 4239 | Ok(()) |
| 4240 | } |
| 4241 | |
| 4242 | async fn remove_sandbox_state_dir(root: &Path, state_dir: &Path) -> Result<(), Status> { |
| 4243 | validate_sandbox_state_dir(root, state_dir)?; |
no test coverage detected