MCPcopy Create free account
hub / github.com/PLSysSec/wave / min_depth

Function min_depth

src/tcb/path.rs:105–130  ·  view source on GitHub ↗
(components: &OwnedComponents)

Source from the content-addressed store, hash-verified

103#[pure]
104#[trusted]
105pub fn min_depth(components: &OwnedComponents) -> isize {
106 let mut curr_depth = 0;
107 let mut idx = 0;
108 while idx < components.len() {
109 body_invariant!(curr_depth >= 0);
110 match components.lookup(idx) {
111 OwnedComponent::RootDir => {
112 return DEPTH_ERR;
113 } // hacky, but fine for now
114 OwnedComponent::CurDir => {}
115 OwnedComponent::ParentDir => {
116 curr_depth -= 1;
117 }
118 OwnedComponent::Normal(_) => {
119 curr_depth += 1;
120 }
121 };
122 // if curr_depth ever dips below 0, it is illegal
123 // this prevents paths like ../other_sandbox_home
124 if curr_depth < 0 {
125 return curr_depth;
126 }
127 idx += 1;
128 }
129 curr_depth
130}
131
132#[trusted]
133#[ensures(result.is_none() ==> old(!is_symlink(out_path)) )]

Callers 1

resolve_pathFunction · 0.85

Calls 2

lenMethod · 0.45
lookupMethod · 0.45

Tested by

no test coverage detected