ply: initial integration (#9311)

Signed-off-by: David Korczynski <david@adalogics.com>

Signed-off-by: David Korczynski <david@adalogics.com>
This commit is contained in:
DavidKorczynski 2022-12-29 12:06:12 +00:00 committed by GitHub
parent 2bad65327d
commit d9e16a1606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 154 additions and 0 deletions

18
projects/ply/Dockerfile Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/python3
# Copyright 2022 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 git clone --depth=1 https://github.com/dabeaz/ply ply
COPY *.sh *py $SRC/
WORKDIR $SRC/ply

22
projects/ply/build.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/bash -eu
# Copyright 2022 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

View File

@ -0,0 +1,104 @@
#!/usr/bin/python3
# Copyright 2022 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.
"""Fuzzer that creates a simple grammar and parsing routines,
and then uses that to parse the fuzzer data. The grammer and
parsing routines can be extended based on coverage analysis."""
import sys
import atheris
import ply.lex as lex
import ply.yacc as yacc
# A simple lexer
tokens = [
"PLUS",
"MINUS",
"TIMES",
"NUMBER",
]
t_PLUS = r'\+'
t_MINUS = r'-'
t_TIMES = "\*"
t_ignore = ' \t'
def t_NUMBER(t):
r'\d+'
t.value = int(t.value)
return t
def t_ignore_newline(t):
r'\n+'
t.lexer.lineno += t.value.count('\n')
def t_error(t):
pass
# Some simple parser rules. Note that grammar rules are written as docstrings
# in each function.
def p_expression(p):
'''
expression : term PLUS term
| term MINUS term
'''
p[0] = ('binop', p[2], p[1], p[3])
def p_expression_term(p):
'''
expression : term
'''
p[0] = p[1]
def p_term(p):
'''
term : factor TIMES factor
'''
p[0] = ('binop', p[2], p[1], p[3])
def p_term_factor(p):
'''
term : factor
'''
p[0] = p[1]
def p_factor_number(p):
'''
factor : NUMBER
'''
p[0] = ('number', p[1])
def p_error(p):
pass
# end of parser functions
def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)
lex.lex()
parser = yacc.yacc()
try:
parser.parse(fdp.ConsumeUnicodeNoSurrogates(sys.maxsize))
except lex.LexError:
pass
def main():
atheris.instrument_all()
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
atheris.Fuzz()
if __name__ == "__main__":
main()

10
projects/ply/project.yaml Normal file
View File

@ -0,0 +1,10 @@
fuzzing_engines:
- libfuzzer
homepage: https://github.com/dabeaz/ply
language: python
main_repo: https://github.com/dabeaz/ply
sanitizers:
- address
- undefined
vendor_ccs:
- david@adalogics.com