From b0b7a3c3187600c6ae773d40e2495db85ccd3cc0 Mon Sep 17 00:00:00 2001 From: Arthur Chan Date: Fri, 15 Jul 2022 15:08:23 +0100 Subject: psycopg2: initial integration (#7773) * psycopg2: initial integration build initial fuzzer * Fix Dockerfile Fix error handling * Fix data length Fix formatting * Fix fuzzer * Fix project contact --- projects/psycopg2/Dockerfile | 24 +++++++++++++++++++++++ projects/psycopg2/build.sh | 24 +++++++++++++++++++++++ projects/psycopg2/fuzz_sql.py | 43 ++++++++++++++++++++++++++++++++++++++++++ projects/psycopg2/project.yaml | 12 ++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 projects/psycopg2/Dockerfile create mode 100644 projects/psycopg2/build.sh create mode 100644 projects/psycopg2/fuzz_sql.py create mode 100644 projects/psycopg2/project.yaml diff --git a/projects/psycopg2/Dockerfile b/projects/psycopg2/Dockerfile new file mode 100644 index 00000000..4ffab027 --- /dev/null +++ b/projects/psycopg2/Dockerfile @@ -0,0 +1,24 @@ +# 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 apt-get install libpq-dev postgresql -y + +RUN git clone https://github.com/psycopg/psycopg2 +WORKDIR psycopg2 + +COPY build.sh fuzz_*.py $SRC/ diff --git a/projects/psycopg2/build.sh b/projects/psycopg2/build.sh new file mode 100644 index 00000000..0428cf98 --- /dev/null +++ b/projects/psycopg2/build.sh @@ -0,0 +1,24 @@ +#!/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. +# +################################################################################ + +# Build and install project (using current CFLAGS, CXXFLAGS). +pip3 install --upgrade pip +pip3 install . + +for fuzzer in $(find $SRC -name 'fuzz_*.py'); do + compile_python_fuzzer $fuzzer +done diff --git a/projects/psycopg2/fuzz_sql.py b/projects/psycopg2/fuzz_sql.py new file mode 100644 index 00000000..2b802ba8 --- /dev/null +++ b/projects/psycopg2/fuzz_sql.py @@ -0,0 +1,43 @@ +#!/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. + +import atheris +from psycopg2 import sql + +def TestInput(data): + fdp = atheris.FuzzedDataProvider(data) + + try: + # Create an SQL statement and perform a set of operations on it. + query = sql.SQL(fdp.ConsumeString(100)) + i1 = sql.Identifier(fdp.ConsumeString(25)) + i2 = sql.Identifier(fdp.ConsumeString(25)) + i3 = sql.Identifier(fdp.ConsumeString(25)) + i4 = sql.Identifier(fdp.ConsumeString(25)) + i5 = sql.Identifier(fdp.ConsumeString(25)) + q1 = sql.SQL(fdp.ConsumeString(100)) + q1.join([i1, i2]) + query.format(q1, i3, i4) + comp = sql.Composed([query, i5]) + except (TypeError, ValueError) as e: + pass + +def main(): + atheris.instrument_all() + atheris.Setup(sys.argv, TestInput, enable_python_coverage=True) + atheris.Fuzz() + +if __name__ == "__main__": + main() diff --git a/projects/psycopg2/project.yaml b/projects/psycopg2/project.yaml new file mode 100644 index 00000000..1f9c5b2f --- /dev/null +++ b/projects/psycopg2/project.yaml @@ -0,0 +1,12 @@ +fuzzing_engines: +- libfuzzer +homepage: https://github.com/psycopg/psycopg2 +language: python +main_repo: https://github.com/psycopg/psycopg2 +primary_contact: "daniele.varrazzo@gmail.com" +sanitizers: +- address +vendor_ccs: +- david@adalogics.com +- adam@adalogics.com +- arthur.chan@adalogics.com -- cgit v1.2.3