A deletion is a working-copy operation, not a new claim about graph paths. Refuse malformed paths and symlink traversal before deleting anything.
(root: &std::path::Path, path: &str)
| 154 | // A deletion is a working-copy operation, not a new claim about graph paths. |
| 155 | // Refuse malformed paths and symlink traversal before deleting anything. |
| 156 | fn deletion_path(root: &std::path::Path, path: &str) -> Result<std::path::PathBuf, String> { |
| 157 | use std::path::Component; |
| 158 | let relative = std::path::Path::new(path); |
| 159 | if path.is_empty() |
| 160 | || relative |
| 161 | .components() |
| 162 | .any(|c| !matches!(c, Component::Normal(_))) |
| 163 | || relative.starts_with(".atomic") |
| 164 | || relative.starts_with(".atomic-sandbox") |
| 165 | { |
| 166 | return Err(format!("invalid stashed deletion path: {path}")); |
| 167 | } |
| 168 | let mut destination = root.to_path_buf(); |
| 169 | for component in relative.components() { |
| 170 | destination.push(component); |
| 171 | match std::fs::symlink_metadata(&destination) { |
| 172 | Ok(meta) if meta.file_type().is_symlink() => { |
| 173 | return Err(format!("refusing stashed deletion through symlink: {path}")); |
| 174 | } |
| 175 | Ok(_) => {} |
| 176 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} |
| 177 | Err(e) => return Err(format!("cannot inspect stashed deletion {path}: {e}")), |
| 178 | } |
| 179 | } |
| 180 | Ok(destination) |
| 181 | } |
| 182 | |
| 183 | /// One stash: an orphan view plus its parsed metadata. |
| 184 | #[derive(Debug, Clone)] |
no test coverage detected