aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Arthur Chan <arthur.chan@adalogics.com>2022-07-15 15:08:23 +0100
committerGravatar GitHub <noreply@github.com>2022-07-15 16:08:23 +0200
commitb0b7a3c3187600c6ae773d40e2495db85ccd3cc0 (patch)
treed257c568a286457f93ef447de454f64453ce1644
parent705ddb4a80048aa5c1afbbe6ab1d4cc372d9f609 (diff)
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
-rw-r--r--projects/psycopg2/Dockerfile24
-rw-r--r--projects/psycopg2/build.sh24
-rw-r--r--projects/psycopg2/fuzz_sql.py43
-rw-r--r--projects/psycopg2/project.yaml12
4 files changed, 103 insertions, 0 deletions
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