MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / validate_mount_subpath

Function validate_mount_subpath

crates/openshell-core/src/driver_mounts.rs:59–78  ·  view source on GitHub ↗

Validate a relative subpath inside a runtime-managed mount source.

(subpath: &str)

Source from the content-addressed store, hash-verified

57
58/// Validate a relative subpath inside a runtime-managed mount source.
59pub 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.
81pub fn validate_container_mount_target(target: &str) -> Result<(), String> {

Callers 2

reject_subpathFunction · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected