-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_path_operations.rs
More file actions
64 lines (56 loc) · 1.73 KB
/
Copy pathfuzz_path_operations.rs
File metadata and controls
64 lines (56 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
//! Fuzz Target: Path Operations
//!
//! Tests path handling for:
//! - Path traversal attacks
//! - Symlink attacks
//! - Unicode paths
//! - Invalid characters
//! - Extreme lengths
#![no_main]
use libfuzzer_sys::fuzz_target;
use tempfile::TempDir;
use vsh::commands::mkdir;
use vsh::state::ShellState;
fuzz_target!(|data: &[u8]| {
// Convert to string
if let Ok(path) = std::str::from_utf8(data) {
// Limit length
if path.len() > 500 {
return;
}
// Skip empty paths
if path.is_empty() {
return;
}
// Create sandbox
let temp = match TempDir::new() {
Ok(t) => t,
Err(_) => return,
};
let mut state = match ShellState::new(temp.path()) {
Ok(s) => s,
Err(_) => return,
};
// Try to create directory with fuzzed path
// Should either succeed (safe path) or fail gracefully (invalid path)
// Should NEVER:
// - Escape sandbox
// - Execute commands
// - Cause panic
let _ = mkdir(&mut state, path, true);
// Verify sandbox integrity (no escape)
if let Ok(canonical_root) = std::fs::canonicalize(temp.path()) {
for entry in walkdir::WalkDir::new(temp.path()).into_iter().flatten() {
if let Ok(canonical) = std::fs::canonicalize(entry.path()) {
assert!(
canonical.starts_with(&canonical_root),
"Path escaped sandbox: {:?}",
canonical
);
}
}
}
}
});