Skip to content

Commit 57a0905

Browse files
committed
Add some fuzzing with cargo-fuzz.
Depends on graphql-rust#1032.
1 parent 2b34ab0 commit 57a0905

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

fuzz/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target
2+
corpus
3+
artifacts

fuzz/Cargo.toml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "fuzz"
3+
version = "0.0.0"
4+
authors = ["Automatically generated"]
5+
publish = false
6+
edition = "2018"
7+
8+
[package.metadata]
9+
cargo-fuzz = true
10+
11+
[dependencies]
12+
libfuzzer-sys = { version = "0.4", features = ["arbitrary-derive"] }
13+
apollo-smith = "0.1.0"
14+
15+
[dependencies.juniper]
16+
path = "../juniper"
17+
features = ["arbitrary1"]
18+
19+
# Prevent this from interfering with workspaces
20+
[workspace]
21+
members = ["."]
22+
23+
[[bin]]
24+
name = "document_fuzzer"
25+
path = "fuzz_targets/document_fuzzer.rs"
26+
test = false
27+
doc = false
28+
29+
[[bin]]
30+
name = "introspection_fuzzer"
31+
path = "fuzz_targets/introspection_fuzzer.rs"
32+
test = false
33+
doc = false

fuzz/fuzz_targets/document_fuzzer.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![no_main]
2+
use apollo_smith::DocumentBuilder;
3+
use libfuzzer_sys::{
4+
arbitrary::{self, Unstructured},
5+
fuzz_target,
6+
};
7+
8+
use juniper::{DefaultScalarValue, EmptyMutation, EmptySubscription, GraphQLObject, RootNode};
9+
10+
#[derive(Default, GraphQLObject, arbitrary::Arbitrary)]
11+
struct Query {
12+
x: i32,
13+
y: String,
14+
z: Vec<bool>,
15+
}
16+
17+
fuzz_target!(|input: &[u8]| {
18+
let mut u = Unstructured::new(input);
19+
let mut u2 = Unstructured::new(input);
20+
if let Ok(gql_doc) = DocumentBuilder::new(&mut u) {
21+
let document = gql_doc.finish();
22+
let doc = String::from(document);
23+
24+
let arbitrary_schema: arbitrary::Result<
25+
RootNode<Query, EmptyMutation<()>, EmptySubscription<()>, DefaultScalarValue>,
26+
> = u2.arbitrary();
27+
28+
if let Ok(schema) = arbitrary_schema {
29+
let _ = juniper::parser::parse_document_source(doc.as_str(), &schema.schema);
30+
}
31+
}
32+
});
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![no_main]
2+
use libfuzzer_sys::{
3+
arbitrary::{self, Unstructured},
4+
fuzz_target,
5+
};
6+
7+
use juniper::{
8+
DefaultScalarValue, EmptyMutation, EmptySubscription, GraphQLObject, IntrospectionFormat,
9+
};
10+
11+
#[derive(Default, GraphQLObject, arbitrary::Arbitrary)]
12+
struct Query {
13+
x: i32,
14+
y: String,
15+
z: Vec<bool>,
16+
}
17+
18+
fuzz_target!(|input: &[u8]| {
19+
let mut u = Unstructured::new(input);
20+
let arbitrary_schema: arbitrary::Result<
21+
juniper::RootNode<Query, EmptyMutation<()>, EmptySubscription<()>, DefaultScalarValue>,
22+
> = u.arbitrary();
23+
24+
if let Ok(schema) = arbitrary_schema {
25+
let _ = juniper::introspect(&schema, &(), IntrospectionFormat::default());
26+
}
27+
});

0 commit comments

Comments
 (0)