Skip to content

Commit

Permalink
Add a simple fuzz tester, from Linux & nightly - cargo fuzz run fuzz_…
Browse files Browse the repository at this point in the history
…target_1
  • Loading branch information
locka99 committed Feb 13, 2022
1 parent d3621a1 commit 8701d1f
Show file tree
Hide file tree
Showing 4 changed files with 325 additions and 0 deletions.
3 changes: 3 additions & 0 deletions types/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
corpus
artifacts
281 changes: 281 additions & 0 deletions types/fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions types/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "opcua-types-fuzz"
version = "0.0.0"
authors = ["Automatically generated"]
publish = false
edition = "2018"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.opcua-types]
path = ".."

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

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

use opcua_types::*;
use std::io::Cursor;

pub fn deserialize(data: &[u8], decoding_options: &DecodingOptions) -> Result<Variant, StatusCode> {
// Decode this, don't expect panics or whatever
let mut stream = Cursor::new(data);
Variant::decode(&mut stream, &decoding_options)
}

fuzz_target!(|data: &[u8]| {
let decoding_options = DecodingOptions::default();
let _ = deserialize(data, &decoding_options);
});

0 comments on commit 8701d1f

Please sign in to comment.