aboutsummaryrefslogtreecommitdiff
path: root/projects/libpg_query
diff options
context:
space:
mode:
authorDavidKorczynski <david@adalogics.com>2021-05-06 14:15:50 +0100
committerGitHub <noreply@github.com>2021-05-06 09:15:50 -0400
commit993575b929de283034a6a31e202e2fcc6b67c1bd (patch)
treeb7f0d9c8c6102d665da89767b3f995b9f60bb002 /projects/libpg_query
parent9a492d4090d4ce3c28f8bdaea7bc8ed753053c35 (diff)
downloadoss-fuzz-993575b929de283034a6a31e202e2fcc6b67c1bd.tar.gz
libpg_query: initial integration. (#5687)
* libpg_query: initial integration.
Diffstat (limited to 'projects/libpg_query')
-rw-r--r--projects/libpg_query/Dockerfile21
-rwxr-xr-xprojects/libpg_query/build.sh19
-rw-r--r--projects/libpg_query/fuzz_parser.c33
-rw-r--r--projects/libpg_query/project.yaml6
4 files changed, 79 insertions, 0 deletions
diff --git a/projects/libpg_query/Dockerfile b/projects/libpg_query/Dockerfile
new file mode 100644
index 000000000..1fef8ae95
--- /dev/null
+++ b/projects/libpg_query/Dockerfile
@@ -0,0 +1,21 @@
+# 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/pganalyze/libpg_query libpg_query
+WORKDIR libpg_query
+COPY build.sh $SRC/
+COPY fuzz_parser.c $SRC/libpg_query/fuzz_parser.c
diff --git a/projects/libpg_query/build.sh b/projects/libpg_query/build.sh
new file mode 100755
index 000000000..f1ac573e1
--- /dev/null
+++ b/projects/libpg_query/build.sh
@@ -0,0 +1,19 @@
+#!/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.
+#
+################################################################################
+
+make build
+$CC $CFLAGS $LIB_FUZZING_ENGINE ./fuzz_parser.c ./libpg_query.a -I./ -o $OUT/fuzz_parser
diff --git a/projects/libpg_query/fuzz_parser.c b/projects/libpg_query/fuzz_parser.c
new file mode 100644
index 000000000..8003da31d
--- /dev/null
+++ b/projects/libpg_query/fuzz_parser.c
@@ -0,0 +1,33 @@
+/* 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.
+*/
+
+#include <pg_query.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ char *new_str = (char *)malloc(size+1);
+ if (new_str == NULL){
+ return 0;
+ }
+ memcpy(new_str, data, size);
+ new_str[size] = '\0';
+
+ PgQueryParseResult result = pg_query_parse(new_str);
+ pg_query_free_parse_result(result);
+
+ free(new_str);
+ return 0;
+}
diff --git a/projects/libpg_query/project.yaml b/projects/libpg_query/project.yaml
new file mode 100644
index 000000000..765711dbb
--- /dev/null
+++ b/projects/libpg_query/project.yaml
@@ -0,0 +1,6 @@
+homepage: "https://pganalyze.com/"
+language: c
+primary_contact: "team@pganalyze.com"
+main_repo: "https://github.com/pganalyze/pg_query"
+auto_ccs:
+ - david@adalogics.com