-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuzz): Adds a fuzz harness for the starlark executor (#64)
Summary: This PR adds a basic fuzz test for the starlark parser and executor. The fuzzer has found a couple of non-critical bugs already :) so hopefully it'll be of some use to you :) X-link: facebook/starlark-rust#64 Reviewed By: stepancheg Differential Revision: D43697975 Pulled By: ndmitchell fbshipit-source-id: f8274390e804bafc4003d7018930ede14a506dd4
- Loading branch information
1 parent
630a353
commit 0cf4c9f
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
target | ||
corpus | ||
artifacts | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "starlark-fuzz" | ||
version = "0.0.0" | ||
publish = false | ||
edition = "2021" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
anyhow = "1.0.69" | ||
libfuzzer-sys = "0.4" | ||
starlark.path = ".." | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[profile.release] | ||
debug = 1 | ||
|
||
[[bin]] | ||
name = "starlark" | ||
path = "fuzz_targets/starlark.rs" | ||
test = false | ||
doc = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2019 The Starlark in Rust Authors. | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#![no_main] | ||
|
||
use std::hint::black_box; | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use starlark::environment::Globals; | ||
use starlark::environment::Module; | ||
use starlark::eval::Evaluator; | ||
use starlark::syntax::AstModule; | ||
use starlark::syntax::Dialect; | ||
|
||
fn run_arbitrary_starlark(content: &str) -> anyhow::Result<()> { | ||
let ast: AstModule = | ||
AstModule::parse("hello_world.star", content.to_owned(), &Dialect::Standard)?; | ||
let globals: Globals = Globals::standard(); | ||
let module: Module = Module::new(); | ||
let mut eval: Evaluator = Evaluator::new(&module); | ||
let value = black_box(eval.eval_module(ast, &globals)?); | ||
_ = black_box(format!("{value:?}")); | ||
return Ok(()); | ||
} | ||
|
||
fuzz_target!(|content: &str| { | ||
if let Err(e) = black_box(run_arbitrary_starlark(content)) { | ||
_ = black_box(format!("{e:?}")); | ||
} | ||
}); |