aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavidKorczynski <david@adalogics.com>2021-03-21 02:48:41 +0000
committerGitHub <noreply@github.com>2021-03-20 19:48:41 -0700
commitf20cbafaa33e5d2f222d954fe22ca11c38c3fac3 (patch)
treec27ced2424dcb754617144cab975d2b775d3f80a
parent9afd3b24a6e3cb7910e32ce1c0bde59213d89b49 (diff)
downloadoss-fuzz-f20cbafaa33e5d2f222d954fe22ca11c38c3fac3.tar.gz
nom: initial integration (#5403)
* initial integration of nom. * Updated maintainer email. * cleanup.
-rw-r--r--projects/nom/Dockerfile22
-rwxr-xr-xprojects/nom/build.sh20
-rw-r--r--projects/nom/fuzz/Cargo.toml24
-rw-r--r--projects/nom/fuzz/fuzz_targets/fuzz_arithmetic.rs71
-rw-r--r--projects/nom/project.yaml10
5 files changed, 147 insertions, 0 deletions
diff --git a/projects/nom/Dockerfile b/projects/nom/Dockerfile
new file mode 100644
index 000000000..946201452
--- /dev/null
+++ b/projects/nom/Dockerfile
@@ -0,0 +1,22 @@
+# Copyright 2021 Google LLC
+#
+# 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
+#
+# http://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.
+#
+################################################################################
+FROM gcr.io/oss-fuzz-base/base-builder
+
+RUN git clone --depth 1 https://github.com/Geal/nom/
+COPY fuzz $SRC/nom/fuzz
+WORKDIR $SRC
+
+COPY build.sh $SRC/
diff --git a/projects/nom/build.sh b/projects/nom/build.sh
new file mode 100755
index 000000000..8567ddc5d
--- /dev/null
+++ b/projects/nom/build.sh
@@ -0,0 +1,20 @@
+#!/bin/bash -eu
+# Copyright 2021 Google LLC
+#
+# 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
+#
+# http://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.
+#
+################################################################################
+
+cd $SRC/nom
+cargo fuzz build -O
+cp fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_arithmetic $OUT/
diff --git a/projects/nom/fuzz/Cargo.toml b/projects/nom/fuzz/Cargo.toml
new file mode 100644
index 000000000..ebb6be68b
--- /dev/null
+++ b/projects/nom/fuzz/Cargo.toml
@@ -0,0 +1,24 @@
+
+[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"
diff --git a/projects/nom/fuzz/fuzz_targets/fuzz_arithmetic.rs b/projects/nom/fuzz/fuzz_targets/fuzz_arithmetic.rs
new file mode 100644
index 000000000..d548dcc94
--- /dev/null
+++ b/projects/nom/fuzz/fuzz_targets/fuzz_arithmetic.rs
@@ -0,0 +1,71 @@
+#![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"),
+ };
+});
diff --git a/projects/nom/project.yaml b/projects/nom/project.yaml
new file mode 100644
index 000000000..9c2f7d840
--- /dev/null
+++ b/projects/nom/project.yaml
@@ -0,0 +1,10 @@
+homepage: "https://github.com/Geal/nom"
+main_repo: "https://github.com/Geal/nom"
+primary_contact: "geo.couprie@gmail.com"
+sanitizers:
+ - address
+fuzzing_engines:
+ - libfuzzer
+language: rust
+auto_ccs:
+ - "david@adalogics.com"