Validate a relative subpath inside a runtime-managed mount source.
(subpath: &str)
| 57 | |
| 58 | /// Validate a relative subpath inside a runtime-managed mount source. |
| 59 | pub fn validate_mount_subpath(subpath: &str) -> Result<(), String> { |
| 60 | if subpath.is_empty() { |
| 61 | return Err("mount subpath must not be empty".to_string()); |
| 62 | } |
| 63 | if subpath != subpath.trim() { |
| 64 | return Err("mount subpath must not contain surrounding whitespace".to_string()); |
| 65 | } |
| 66 | if subpath.as_bytes().contains(&0) { |
| 67 | return Err("mount subpath must not contain NUL bytes".to_string()); |
| 68 | } |
| 69 | let path = Path::new(subpath); |
| 70 | if path.is_absolute() |
| 71 | || path |
| 72 | .components() |
| 73 | .any(|component| matches!(component, std::path::Component::ParentDir)) |
| 74 | { |
| 75 | return Err("mount subpath must be relative and must not contain '..'".to_string()); |
| 76 | } |
| 77 | Ok(()) |
| 78 | } |
| 79 | |
| 80 | /// Validate a container-side mount target for user-supplied driver mounts. |
| 81 | pub fn validate_container_mount_target(target: &str) -> Result<(), String> { |
no test coverage detected