Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • redox-os/redoxfs
  • jD91mZM2/redoxfs
  • microcolonel/redoxfs
  • rm-dr/redoxfs
  • deepaksirone/redoxfs
  • sevenEng/redoxfs
  • mortona/redoxfs
  • potatogim/redoxfs
  • 4lDO2/redoxfs
  • malandrakisgeo/redoxfs
  • ssd/redoxfs
  • dahc/redoxfs
  • ashton/redoxfs
  • usapmz/redoxfs
  • vadorovsky/redoxfs
  • bjorn3/redoxfs
  • rw_van/redoxfs
  • mkroening/redoxfs
  • emaxx-g/redoxfs
  • CILP/redoxfs
  • AnandSMain/redoxfs
  • aaronjanse/redoxfs
  • liamnprg/redoxfs
  • coolreader18/redoxfs
  • freewilll/redoxfs
  • adi-g15/redoxfs
  • andrey.turkin/redoxfs
  • matlik/redoxfs
28 results
Show changes
Commits on Source (4)
target
corpus
artifacts
coverage
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "aes"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
"opaque-debug",
]
[[package]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]]
name = "arbitrary"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d5a26814d8dcb93b0e5a0ff3c6d80a8843bafb21b39e8e18a6f05471870e110"
dependencies = [
"derive_arbitrary",
]
[[package]]
name = "argon2"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25df3c03f1040d0069fcd3907e24e36d59f9b6fa07ba49be0eb25a794f036ba7"
dependencies = [
"base64ct",
"blake2",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "base64ct"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "blake2"
version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe"
dependencies = [
"digest",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cc"
version = "1.0.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc"
dependencies = [
"libc",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cipher"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
dependencies = [
"generic-array",
]
[[package]]
name = "cpufeatures"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "derive_arbitrary"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
"subtle",
]
[[package]]
name = "env_logger"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "fuser"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5910691a0ececcc6eba8bb14029025c2d123e96a53db1533f6a4602861a5aaf7"
dependencies = [
"libc",
"log",
"memchr",
"page_size",
"pkg-config",
"smallvec",
"users",
"zerocopy",
]
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
]
[[package]]
name = "getrandom"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5"
dependencies = [
"cfg-if",
"libc",
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "libc"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libfuzzer-sys"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a96cfd5557eb82f2b83fed4955246c988d331975a002961b07c81584d107e7f7"
dependencies = [
"arbitrary",
"cc",
"once_cell",
]
[[package]]
name = "log"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
[[package]]
name = "memchr"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "numtoa"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "opaque-debug"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]]
name = "page_size"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "pkg-config"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec"
[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "range-tree"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384c2842d4e069d5ccacf5fe1dca4ef8d07a5444329715f0fc3c61813502d4d1"
[[package]]
name = "redox-path"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d515f4eec916ba5ea351bd7ad7b25232af420282e88c932b29b2a4e807538e19"
[[package]]
name = "redox_simple_endian"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "175b27da3d5db1502bd20ae0917ba132d256a2b169f1686681304ebb86504eab"
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_syscall"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_termios"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20145670ba436b55d91fc92d25e71160fbfbdd57831631c8d7d36377a476f1cb"
[[package]]
name = "redoxfs"
version = "0.6.0"
dependencies = [
"aes",
"argon2",
"base64ct",
"env_logger",
"fuser",
"getrandom",
"libc",
"log",
"range-tree",
"redox-path",
"redox_simple_endian",
"redox_syscall 0.4.1",
"seahash",
"termion",
"time",
"uuid",
]
[[package]]
name = "redoxfs-fuzz"
version = "0.0.0"
dependencies = [
"libfuzzer-sys",
"redox_syscall 0.4.1",
"redoxfs",
]
[[package]]
name = "regex"
version = "1.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "seahash"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b"
[[package]]
name = "smallvec"
version = "1.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
[[package]]
name = "subtle"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]]
name = "syn"
version = "2.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "termcolor"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
dependencies = [
"winapi-util",
]
[[package]]
name = "termion"
version = "1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
dependencies = [
"libc",
"numtoa",
"redox_syscall 0.2.16",
"redox_termios",
]
[[package]]
name = "time"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "users"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
dependencies = [
"libc",
"log",
]
[[package]]
name = "uuid"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f00cc9702ca12d3c81455259621e676d0f7251cec66a21e98fe2e9a37db93b2a"
dependencies = [
"getrandom",
]
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "zerocopy"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[package]
name = "redoxfs-fuzz"
version = "0.0.0"
publish = false
edition = "2021"
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = { version = "0.4.0", features = ["arbitrary-derive"] }
redox_syscall = "0.4"
[dependencies.redoxfs]
path = ".."
[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
test = false
doc = false
bench = false
[[bin]]
name = "fuse_1"
path = "fuzz_targets/fuse_1.rs"
test = false
doc = false
bench = false
#![no_main]
use std::collections::HashMap;
use std::ops::DerefMut;
use std::path::{Component, Path, PathBuf};
use std::process::Command;
use std::{fs, sync, thread, time};
use redoxfs::{unmount_path, DiskSparse, FileSystem};
use libfuzzer_sys::fuzz_target;
use libfuzzer_sys::arbitrary;
use libfuzzer_sys::arbitrary::Arbitrary;
#[derive(Arbitrary, Debug, Clone)]
enum FilesystemAction {
CreateFile {
path: String,
contents: String,
},
WriteFile {
index: u32,
contents: String,
},
ReadFile { // and verify
index: u32,
},
DeleteFile {
index: u32
},
//read/delete/rename file that doesn't exist
}
// VERY slow
fuzz_target!(|actions: Vec<FilesystemAction>| {
with_redoxfs(move |real_path| {
let mut paths = vec![];
let mut hashmap = HashMap::new();
for action in &actions {
match action {
FilesystemAction::CreateFile { path, contents } => {
if path.is_empty() {
continue;
}
if path.len() >= 252 {
continue;
}
if PathBuf::from(path).components().any(| x | x == Component::ParentDir) {
continue;
}
if !path.is_ascii() || path.contains(| ch: char | !ch.is_alphanumeric() ) { // || path.contains(&['\0', '\n', '\t'])
continue;
}
if contents.contains('\0') {
continue;
}
let path = real_path.join(path);
if paths.contains(&path) {
continue;
}
fs::write(&path, contents).unwrap();
hashmap.insert(path.clone(), contents);
paths.push(path);
},
FilesystemAction::WriteFile { index, contents } => {
if paths.len() == 0 {
continue;
}
if contents.contains('\0') {
continue;
}
let path = &paths[*index as usize % paths.len()];
hashmap.insert(path.clone(), contents);
fs::write(path, contents).unwrap();
},
FilesystemAction::ReadFile { index } => {
if paths.len() == 0 {
continue;
}
let path = &paths[*index as usize % paths.len()];
let contets = fs::read_to_string(path).unwrap();
let real_contets = hashmap.get(path).unwrap().to_string();
assert_eq!(contets, real_contets);
},
FilesystemAction::DeleteFile { index } => {
if paths.len() == 0 {
continue;
}
let path = &paths[*index as usize % paths.len()].clone();
paths.remove(*index as usize % paths.len());
fs::remove_file(path).unwrap();
hashmap.remove(path);
},
//_ => ()
}
}
})
});
fn with_redoxfs<T, F>(callback: F) -> T
where
T: Send + Sync + 'static,
F: FnMut(&Path) -> T + Send + Sync + 'static,
{
let disk_path = "/tmp/fuzzer-image.img";
let mount_path = "/tmp/image";
let res = {
let disk = DiskSparse::create(disk_path, 1024 * 1024 * 5).unwrap();
if cfg!(not(target_os = "redox")) {
if !Path::new(mount_path).exists() {
(fs::create_dir(mount_path)).unwrap();
}
}
let ctime = (time::SystemTime::now().duration_since(time::UNIX_EPOCH)).unwrap();
let fs = FileSystem::create(disk, None, ctime.as_secs(), ctime.subsec_nanos()).unwrap();
let callback_mutex = sync::Arc::new(sync::Mutex::new(callback));
let join_handle = redoxfs::mount(fs, mount_path, move |real_path| {
let callback_mutex = callback_mutex.clone();
let real_path = real_path.to_owned();
thread::spawn(move || {
let res = {
let mut callback_guard = callback_mutex.lock().unwrap();
let callback = callback_guard.deref_mut();
callback(&real_path)
};
if cfg!(target_os = "redox") {
fs::remove_file(format!(":{}", mount_path)).unwrap();
} else {
while !(Command::new("sync").status()).unwrap().success() {
}
while !unmount_path(mount_path).is_ok() {
}
}
res
})
})
.unwrap();
join_handle.join().unwrap()
};
fs::remove_file(disk_path).unwrap();
if cfg!(not(target_os = "redox")) {
fs::remove_dir(mount_path).unwrap();
}
res
}
#![no_main]
#![feature(io_error_uncategorized)]
mod helper;
use std::path::Path;
use std::{fs, io, time};
use std::io::ErrorKind;
use redoxfs::{DiskSparse, FileSystem, Node, TreePtr};
use libfuzzer_sys::arbitrary::Arbitrary;
use libfuzzer_sys::arbitrary;
#[derive(Arbitrary, Debug, Clone)]
enum FilesystemAction {
CreateFile {
path: String,
contents: String,
},
WriteFile {
index: u32,
contents: String,
},
ReadFile { // and verify
index: u32,
},
DeleteFile {
index: u32
},
//read/delete/rename file that doesn't exist
}
impl FilesystemAction {
fn run<'a>(&'a self, fs: &mut FileSystem<DiskSparse>, paths: &mut Vec<&'a Path>) -> Result<(), io::Error> {
let error = fs.tx(|tx| {
let metadata = helper::Metadata::default();
match self {
FilesystemAction::CreateFile { path, contents } => {
if !path.is_ascii() || path.contains(| ch: char | !ch.is_alphanumeric() ) { // || path.contains(&['\0', '\n', '\t'])
return Ok(None);
}
if path.len() >= 252 {
return Ok(None);
}
if contents.contains('\0') {
return Ok(None);
}
let path = Path::new(path);
if path.file_name().is_none() {
return Ok(None);
}
if paths.contains(&path) {
return Ok(None)
}
paths.push(path);
match helper::create_inner(path.as_ref(), Node::MODE_FILE, &metadata, tx) {
Ok(node_ptr) => {
let data = contents.as_bytes();
let count = tx
.write_node(
node_ptr,
0,
&data,
metadata.mtime,
metadata.mtime_nsec,
).unwrap();
if count != data.len() {
panic!("file write count {} != {}", count, data.len());
}
},
Err(e) => { return Ok(Some(e)) },
};
},
FilesystemAction::WriteFile { index, contents } => {
if paths.len() == 0 {
return Ok(None);
}
if contents.contains('\0') {
return Ok(None);
}
let path = paths[*index as usize % paths.len()];
let name = match path.file_name() {
Some(s) => s,
None => panic!("Path is wrong"),
}.to_str().unwrap();
let mut children = vec![];
tx.child_nodes(TreePtr::root(), &mut children).unwrap();
let child = children.into_iter().find(| x | x.name().unwrap() == name).unwrap();
let data = contents.as_bytes();
let count = tx
.write_node(
child.node_ptr(),
0,
&data,
metadata.mtime,
metadata.mtime_nsec,
).unwrap();
if count != data.len() {
panic!("file write count {} != {}", count, data.len());
}
},
/*FilesystemAction::DeleteFile { index } => {
if paths.len() == 0 {
return Ok(None);
}
let path = paths[*index as usize % paths.len()];
let name = match path.file_name() {
Some(s) => s,
None => panic!("Path is wrong"),
}.to_str().unwrap();
let mut children = vec![];
tx.child_nodes(TreePtr::root(), &mut children)?;
let child = children.into_iter().find(| x | x.name().unwrap() == name).unwrap();
tx.remove_node(child.node_ptr(), child.name().unwrap(), Node::MODE_FILE)?;
paths.remove(*index as usize % paths.len());
},*/
FilesystemAction::ReadFile { index } => {
if paths.len() == 0 {
return Ok(None);
}
let path = paths[*index as usize % paths.len()];
let name = match path.file_name() {
Some(s) => s,
None => panic!("Path is wrong"),
}.to_str().unwrap();
let mut children = vec![];
tx.child_nodes(TreePtr::root(), &mut children).unwrap();
let child = children.into_iter().find(| x | x.name().unwrap() == name).unwrap();
let mut buffer: [u8; 1024] = [0; 1024];
tx.read_node(child.node_ptr(), 0, &mut buffer, 0, 0).unwrap();
/*let string = match String::from_utf8(buffer.to_vec()) {
Ok(s) => s,
Err(e) => panic!("Contents are wrong error: {e:?}"),
};*/
// TODO: Validate
},
_ => ()
}
/*tx.sync(true)?;
let end_block = tx.header.size() / BLOCK_SIZE;
tx.header.size = (end_block * BLOCK_SIZE).into();
tx.header_changed = true;*/
tx.sync(true)?;
Ok(None)
}).map_err(|err| io::Error::from_raw_os_error(err.errno))?;
match error {
None => Ok(()),
Some(e) => Err(e)
}
}
}
libfuzzer_sys::fuzz_target!(|actions: Vec<FilesystemAction>| {
//panic!("{actions:#?}");
let disk_path = "/tmp/redox_fuzzer.img";
let _ = fs::remove_file(disk_path);
let disk = DiskSparse::create(disk_path, 1024 * 1024 * 10).unwrap();
let ctime = time::SystemTime::now().duration_since(time::UNIX_EPOCH).unwrap();
let mut fs = FileSystem::create(disk, None, ctime.as_secs(), ctime.subsec_nanos()).unwrap();
//helper::archive(&mut fs, "test").unwrap();
let mut paths = vec![]; // index = index % paths.len()
for action in &actions {
match action.run(&mut fs, &mut paths) {
Ok(_) => (),
Err(e) => match e.kind() {
ErrorKind::InvalidData => (),
ErrorKind::InvalidInput => (),
ErrorKind::AlreadyExists => (),
ErrorKind::OutOfMemory => (),
ErrorKind::Uncategorized => (),
e => panic!("{e}")
}
};
}
});
use std::fs;
use std::io;
use std::os::unix::ffi::OsStrExt;
use std::os::unix::fs::MetadataExt;
use std::path::Path;
use redoxfs::{Disk, FileSystem, Node, Transaction, TreePtr, BLOCK_SIZE};
fn syscall_err(err: syscall::Error) -> io::Error {
io::Error::from_raw_os_error(err.errno)
}
#[derive(Default)]
pub struct Metadata {
pub mode: u16,
pub ctime: u64,
pub ctime_nsec: u32,
pub mtime: u64,
pub mtime_nsec: u32,
pub uid: u32,
pub gid: u32,
}
pub fn create_inner<D: Disk>(path: &Path, mode: u16, metadata: &Metadata, tx: &mut Transaction<D>) -> Result<TreePtr<Node>, io::Error> {
let name = path.file_name().ok_or(io::Error::from(io::ErrorKind::InvalidData))?.to_str().ok_or(
io::Error::new(io::ErrorKind::InvalidData, "filename is not valid UTF-8")
)?;
let parent_ptr = TreePtr::root();
let node_ptr;
{
let mode = mode | (metadata.mode as u16 & Node::MODE_PERM);
let mut node = tx
.create_node(
parent_ptr,
&name,
mode,
metadata.ctime as u64,
metadata.ctime_nsec as u32,
)
.map_err(syscall_err)?;
node_ptr = node.ptr();
if node.data().uid() != metadata.uid || node.data().gid() != metadata.gid {
node.data_mut().set_uid(metadata.uid);
node.data_mut().set_gid(metadata.gid);
tx.sync_tree(node).map_err(syscall_err)?;
}
}
Ok(node_ptr)
}
pub fn create_file<D: Disk, P: AsRef<Path>>(fs: &mut FileSystem<D>, path: P, contents: String) -> Result<(), io::Error>{
let error = fs.tx(|tx| {
let metadata = Metadata {
mode: 0,
ctime: 0,
ctime_nsec: 0,
mtime: 0,
mtime_nsec: 0,
uid: 0,
gid: 0,
};
let mode = Node::MODE_FILE;
match create_inner(path.as_ref(), mode, &metadata, tx) {
Ok(node_ptr) => {
let data = contents.as_bytes();
let count = tx
.write_node(
node_ptr,
0,
&data,
metadata.mtime,
metadata.mtime_nsec,
)?;
if count != data.len() {
panic!("file write count {} != {}", count, data.len());
}
},
Err(e) => { return Ok(Some(e)) },
};
/*tx.sync(true)?;
let end_block = tx.header.size() / BLOCK_SIZE;
tx.header.size = (end_block * BLOCK_SIZE).into();
tx.header_changed = true;*/
tx.sync(false)?;
Ok(None)
}).map_err(syscall_err)?;
match error {
None => Ok(()),
Some(e) => Err(e)
}
}
pub fn create_empty_file<D: Disk, P: AsRef<Path>>(fs: &mut FileSystem<D>, path: P) -> Result<(), io::Error>{
let error = fs.tx(|tx| {
let metadata = Metadata {
mode: 0,
ctime: 0,
ctime_nsec: 0,
mtime: 0,
mtime_nsec: 0,
uid: 0,
gid: 0,
};
let mode = Node::MODE_FILE;
match create_inner(path.as_ref(), mode, &metadata, tx) {
Ok(_) => { },
Err(e) => { return Ok(Some(e)) },
};
/*tx.sync(true)?;
let end_block = tx.header.size() / BLOCK_SIZE;
tx.header.size = (end_block * BLOCK_SIZE).into();
tx.header_changed = true;*/
tx.sync(false)?;
Ok(None)
}).map_err(syscall_err)?;
match error {
None => Ok(()),
Some(e) => Err(e)
}
}
/*
pub fn archive_at<D: Disk, P: AsRef<Path>>(
tx: &mut Transaction<D>,
parent_path: P,
parent_ptr: TreePtr<Node>,
) -> io::Result<()> {
for entry_res in fs::read_dir(parent_path)? {
let entry = entry_res?;
let metadata = entry.metadata()?;
let file_type = metadata.file_type();
let name = entry.file_name().into_string().map_err(|_| {
io::Error::new(io::ErrorKind::InvalidData, "filename is not valid UTF-8")
})?;
let mode_type = if file_type.is_dir() {
Node::MODE_DIR
} else if file_type.is_file() {
Node::MODE_FILE
} else if file_type.is_symlink() {
Node::MODE_SYMLINK
} else {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Does not support parsing {:?}", file_type),
));
};
let node_ptr;
{
let mode = mode_type | (metadata.mode() as u16 & Node::MODE_PERM);
let mut node = tx
.create_node(
parent_ptr,
&name,
mode,
metadata.ctime() as u64,
metadata.ctime_nsec() as u32,
)
.map_err(syscall_err)?;
node_ptr = node.ptr();
if node.data().uid() != metadata.uid() || node.data().gid() != metadata.gid() {
node.data_mut().set_uid(metadata.uid());
node.data_mut().set_gid(metadata.gid());
tx.sync_tree(node).map_err(syscall_err)?;
}
}
let path = entry.path();
if file_type.is_dir() {
archive_at(tx, path, node_ptr)?;
} else if file_type.is_file() {
let data = fs::read(path)?;
let count = tx
.write_node(
node_ptr,
0,
&data,
metadata.mtime() as u64,
metadata.mtime_nsec() as u32,
)
.map_err(syscall_err)?;
if count != data.len() {
panic!("file write count {} != {}", count, data.len());
}
} else if file_type.is_symlink() {
let destination = fs::read_link(path)?;
let data = destination.as_os_str().as_bytes();
let count = tx
.write_node(
node_ptr,
0,
data,
metadata.mtime() as u64,
metadata.mtime_nsec() as u32,
)
.map_err(syscall_err)?;
if count != data.len() {
panic!("symlink write count {} != {}", count, data.len());
}
} else {
return Err(io::Error::new(
io::ErrorKind::Other,
format!("Does not support creating {:?}", file_type),
));
}
}
Ok(())
}
pub fn archive<D: Disk, P: AsRef<Path>>(fs: &mut FileSystem<D>, parent_path: P) -> io::Result<u64> {
let end_block = fs
.tx(|tx| {
// Archive_at root node
archive_at(tx, parent_path, TreePtr::root())
.map_err(|err| syscall::Error::new(err.raw_os_error().unwrap()))?;
// Squash alloc log
tx.sync(true)?;
let end_block = tx.header.size() / BLOCK_SIZE;
/* TODO: Cut off any free blocks at the end of the filesystem
let mut end_changed = true;
while end_changed {
end_changed = false;
let allocator = fs.allocator();
let levels = allocator.levels();
for level in 0..levels.len() {
let level_size = 1 << level;
for &block in levels[level].iter() {
if block < end_block && block + level_size >= end_block {
end_block = block;
end_changed = true;
}
}
}
}
*/
// Update header
tx.header.size = (end_block * BLOCK_SIZE).into();
tx.header_changed = true;
tx.sync(false)?;
Ok(end_block)
})
.map_err(syscall_err)?;
Ok((fs.block + end_block) * BLOCK_SIZE)
}
*/