Skip to content

Commit

Permalink
fuzzing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Kjäll committed Aug 19, 2020
1 parent b75b501 commit fada646
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cursive/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target
corpus
artifacts
26 changes: 26 additions & 0 deletions cursive/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

[package]
name = "cursive-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.3"

[dependencies.cursive]
path = ".."
default-features = false
features = ["crossterm-backend"]

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
23 changes: 23 additions & 0 deletions cursive/fuzz/fuzz_targets/fuzz_target_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![no_main]
use libfuzzer_sys::fuzz_target;

use cursive::views::{Dialog, TextView};
use std::str;

use std::thread;
use std::time::Duration;

fuzz_target!(|data: &[u8]| {
let str = str::from_utf8(data);
if let Ok(s) = str {
// Creates the cursive root - required for every application.
let mut siv = cursive::default();

// Creates a dialog with a single "Quit" button
siv.add_layer(Dialog::around(TextView::new(s))
.title("Cursive")
.button("Quit", |s| s.quit()));

siv.step();
}
});
9 changes: 9 additions & 0 deletions cursive/src/cursive_runnable.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{backend, backends, Cursive};
use cursive_core::CursiveRunner;

/// A runnable wrapper around `Cursive`, bundling the backend initializer.
///
Expand Down Expand Up @@ -59,6 +60,14 @@ impl CursiveRunnable {
self.try_run().unwrap();
}

/// dummy text
pub fn step(&mut self) {
let mut runner = self.siv.runner((self.backend_init)().unwrap());

runner.refresh();
runner.step();
}

/// Runs the event loop with the registered backend initializer.
pub fn try_run(&mut self) -> Result<(), Box<dyn std::error::Error>> {
self.siv.try_run_with(&mut self.backend_init)
Expand Down

0 comments on commit fada646

Please sign in to comment.