diff --git a/projects/face/Dockerfile b/projects/face/Dockerfile new file mode 100644 index 000000000..96a45e578 --- /dev/null +++ b/projects/face/Dockerfile @@ -0,0 +1,19 @@ +#!/usr/bin/python3 +# Copyright 2023 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-python +RUN pip3 install --upgrade pip +RUN git clone https://github.com/mahmoud/face face +COPY *.sh *py $SRC/ +WORKDIR $SRC/face diff --git a/projects/face/build.sh b/projects/face/build.sh new file mode 100644 index 000000000..dd11fafc6 --- /dev/null +++ b/projects/face/build.sh @@ -0,0 +1,21 @@ +#!/bin/bash -eu +# Copyright 2023 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. +# +################################################################################ +pip3 install . +# Build fuzzers in $OUT. +for fuzzer in $(find $SRC -name 'fuzz_*.py'); do + compile_python_fuzzer $fuzzer +done diff --git a/projects/face/fuzz_command.py b/projects/face/fuzz_command.py new file mode 100644 index 000000000..ab6d2cd60 --- /dev/null +++ b/projects/face/fuzz_command.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 +# Copyright 2023 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. +import sys +import atheris + +import face + + +def empty(): + return + + +def TestOneInput(data): + fdp = atheris.FuzzedDataProvider(data) + args = [] + for idx in range(fdp.ConsumeIntInRange(1, 100)): + args.append(fdp.ConsumeUnicodeNoSurrogates(124)) + + cmd = face.Command(empty, name='fuzz') + for idx in range(fdp.ConsumeIntInRange(1, 15)): + try: + cmd.add(fdp.ConsumeUnicodeNoSurrogates(64), + char=fdp.ConsumeUnicodeNoSurrogates(5), + parse_as=fdp.ConsumeBool(), + doc=fdp.ConsumeUnicodeNoSurrogates(64)) + except face.errors.FaceException: + pass + except ValueError: + # Raised by face: https://github.com/mahmoud/face/blob/eb56873b9081852f4500b1a61f178ca0cc8666bc/face/utils.py#L80 + pass + + # Create a command and parse the args + try: + cmd.parse(args) + except face.errors.FaceException: + pass + + +def main(): + atheris.instrument_all() + atheris.Setup(sys.argv, TestOneInput) + atheris.Fuzz() + + +if __name__ == "__main__": + main() diff --git a/projects/face/fuzz_parse.py b/projects/face/fuzz_parse.py new file mode 100644 index 000000000..fcff66a00 --- /dev/null +++ b/projects/face/fuzz_parse.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 +# Copyright 2023 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. +import sys +import atheris + +import face + + +def TestOneInput(data): + fdp = atheris.FuzzedDataProvider(data) + args = [] + for idx in range(fdp.ConsumeIntInRange(1, 100)): + args.append(fdp.ConsumeUnicodeNoSurrogates(124)) + + # Create a command and parse the args + cmd = face.Command(lambda flag, part: None, name='cmd') + try: + cmd.parse(args) + except face.errors.FaceException: + pass + + +def main(): + atheris.instrument_all() + atheris.Setup(sys.argv, TestOneInput) + atheris.Fuzz() + + +if __name__ == "__main__": + main() diff --git a/projects/face/project.yaml b/projects/face/project.yaml new file mode 100644 index 000000000..0e6f5ca3b --- /dev/null +++ b/projects/face/project.yaml @@ -0,0 +1,10 @@ +homepage: https://github.com/mahmoud/face +main_repo: https://github.com/mahmoud/face +language: python +fuzzing_engines: +- libfuzzer +sanitizers: +- address +- undefined +vendor_ccs: +- david@adalogics.com