Skip to content

Commit 68c79bc

Browse files
committed
add fuzz target for parsing key sequence
1 parent 58eb7ed commit 68c79bc

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "keybinds"
3-
version = "0.0.6"
3+
version = "0.0.7"
44
edition = "2021"
55
authors = ["rhysd <[email protected]>"]
66
description = "Platform&Framework-agnostic key binding (keyboard shortcut) parser and dispatcher"

fuzz/Cargo.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ edition = "2021"
77
[package.metadata]
88
cargo-fuzz = true
99

10+
[features]
11+
default = []
12+
arbitrary = ["dep:arbitrary"]
13+
1014
[dependencies]
11-
arbitrary = "1.4.1"
15+
arbitrary = { version = "1.4.1", optional = true }
1216
keybinds = { path = "..", features = ["arbitrary"] }
1317
libfuzzer-sys = "0.4"
1418

@@ -18,3 +22,11 @@ path = "fuzz_targets/dispatch.rs"
1822
test = false
1923
doc = false
2024
bench = false
25+
required-features = ["arbitrary"]
26+
27+
[[bin]]
28+
name = "parse"
29+
path = "fuzz_targets/parse.rs"
30+
test = false
31+
doc = false
32+
bench = false

fuzz/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ Fuzzing with [cargo-fuzz](https://rust-fuzz.github.io/book/introduction.html).
22

33
```sh
44
# Fuzz dispatching key bindings with random key inputs
5-
cargo +nightly fuzz run dispatch
5+
cargo +nightly fuzz run dispatch --features=arbitrary
6+
7+
# Fuzz parsing a key sequence like "Ctrl+X"
8+
cargo +nightly fuzz run parse
69
```

fuzz/fuzz_targets/parse.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![no_main]
2+
use keybinds::KeySeq;
3+
use libfuzzer_sys::fuzz_target;
4+
5+
fuzz_target!(|data: &[u8]| {
6+
if let Ok(s) = std::str::from_utf8(data) {
7+
let _ = s.parse::<KeySeq>();
8+
}
9+
});

0 commit comments

Comments
 (0)