use the fuzz directory from nom's repository (#5499)

added in 0a499cd123
This commit is contained in:
Geoffroy Couprie 2021-03-25 13:40:30 +01:00 committed by GitHub
parent fccea98eb7
commit 0282c8c495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 95 deletions

View File

@ -1,24 +0,0 @@
[package]
name = "nom-fuzz"
version = "0.0.0"
authors = ["David Korczynski <david@adalogics.com>"]
publish = false
edition = "2018"
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.3"
[dependencies.nom]
path = ".."
# Prevent this from interfering with workspaces
[workspace]
members = ["."]
[[bin]]
name = "fuzz_arithmetic"
path = "fuzz_targets/fuzz_arithmetic.rs"

View File

@ -1,71 +0,0 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use std::str;
extern crate nom;
use nom::{
branch::alt,
bytes::complete::tag,
character::complete::char,
character::complete::{digit1 as digit, space0 as space},
combinator::map_res,
multi::fold_many0,
sequence::{delimited, pair},
IResult,
};
use std::str::FromStr;
fn parens(i: &str) -> IResult<&str, i64> {
delimited(space, delimited(tag("("), expr, tag(")")), space)(i)
}
fn factor(i: &str) -> IResult<&str, i64> {
alt((
map_res(delimited(space, digit, space), FromStr::from_str),
parens,
))(i)
}
fn term(i: &str) -> IResult<&str, i64> {
let (i, init) = factor(i)?;
fold_many0(
pair(alt((char('*'), char('/'))), factor),
init,
|acc, (op, val): (char, i64)| {
if op == '*' {
acc * val
} else {
acc / val
}
},
)(i)
}
fn expr(i: &str) -> IResult<&str, i64> {
let (i, init) = term(i)?;
fold_many0(
pair(alt((char('+'), char('-'))), term),
init,
|acc, (op, val): (char, i64)| {
if op == '+' {
acc + val
} else {
acc - val
}
},
)(i)
}
fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
let temp = match str::from_utf8(data) {
Ok(v) => factor(v),
Err(e) => factor("2"),
};
});