aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yunshu Ouyang <61579667+yooyoo9@users.noreply.github.com>2020-09-11 08:21:59 +0200
committerGravatar GitHub <noreply@github.com>2020-09-11 16:21:59 +1000
commit762ec93d3b333493d475b6885ff4fd83a83dc343 (patch)
treea570dc9c649de13036094be9a3858bd95c9dd542
parent3a2cbe546b0f03129d0d7918dc5bd507c889ffa7 (diff)
[PostgreSQL] Fix startup crashes (#4430)
-rw-r--r--projects/postgresql/build.sh3
-rw-r--r--projects/postgresql/fuzzer/fuzzer_initialize.c33
-rw-r--r--projects/postgresql/fuzzer/json_parser_fuzzer.c6
-rw-r--r--projects/postgresql/fuzzer/simple_query_fuzzer.c7
4 files changed, 28 insertions, 21 deletions
diff --git a/projects/postgresql/build.sh b/projects/postgresql/build.sh
index dd6dd8cc..0cc58006 100644
--- a/projects/postgresql/build.sh
+++ b/projects/postgresql/build.sh
@@ -25,8 +25,7 @@ cd src/backend/fuzzer
su fuzzuser -c "make createdb"
chown -R root .
mv temp/data .
-tar -czvf data.tar.gz data/
-cp data.tar.gz $OUT/
+cp -r data $OUT/
cd ../../..
cp -r tmp_install $OUT/
make clean
diff --git a/projects/postgresql/fuzzer/fuzzer_initialize.c b/projects/postgresql/fuzzer/fuzzer_initialize.c
index c3bada22..0ab9d7dc 100644
--- a/projects/postgresql/fuzzer/fuzzer_initialize.c
+++ b/projects/postgresql/fuzzer/fuzzer_initialize.c
@@ -35,35 +35,44 @@
#include "utils/snapmgr.h"
#include "utils/timeout.h"
+#include <libgen.h>
+
const char *progname;
static MemoryContext row_description_context = NULL;
static StringInfoData row_description_buf;
static const char *username = "username";
-int FuzzerInitialize(char *dbname){
- char *argv[5];
+int FuzzerInitialize(char *dbname, char ***argv){
+ char *av[5];
char arg_path[50];
char path_to_db[50];
char untar[100];
+ char *exe_path = (*argv)[0];
+ //dirname() can modify its argument
+ char *exe_path_copy = strdup(exe_path);
+ char *dir = dirname(exe_path_copy);
+ chdir(dir);
+ free(exe_path_copy);
+
snprintf(arg_path, sizeof(arg_path), "/tmp/%s/data", dbname);
snprintf(path_to_db, sizeof(path_to_db), "-D\"/tmp/%s/data\"", dbname);
- snprintf(untar, sizeof(untar), "rm -rf /tmp/%s && mkdir /tmp/%s && tar -xvf data.tar.gz -C /tmp/%s", dbname, dbname, dbname);
-
- argv[0] = "tmp_install/usr/local/pgsql/bin/postgres";
- argv[1] = path_to_db;
- argv[2] = "-F";
- argv[3] = "-k\"/tmp/pg_dbfuzz\"";
- argv[4] = NULL;
+ snprintf(untar, sizeof(untar), "rm -rf /tmp/%s; mkdir /tmp/%s; cp -r data /tmp/%s", dbname, dbname, dbname);
+
+ av[0] = "tmp_install/usr/local/pgsql/bin/postgres";
+ av[1] = path_to_db;
+ av[2] = "-F";
+ av[3] = "-k\"/tmp\"";
+ av[4] = NULL;
system(untar);
- progname = get_progname(argv[0]);
+ progname = get_progname(av[0]);
MemoryContextInit();
- InitStandaloneProcess(argv[0]);
+ InitStandaloneProcess(av[0]);
SetProcessingMode(InitProcessing);
InitializeGUCOptions();
- process_postgres_switches(4, argv, PGC_POSTMASTER, NULL);
+ process_postgres_switches(4, av, PGC_POSTMASTER, NULL);
SelectConfigFiles(arg_path, progname);
diff --git a/projects/postgresql/fuzzer/json_parser_fuzzer.c b/projects/postgresql/fuzzer/json_parser_fuzzer.c
index 411cfdd7..08a96fd7 100644
--- a/projects/postgresql/fuzzer/json_parser_fuzzer.c
+++ b/projects/postgresql/fuzzer/json_parser_fuzzer.c
@@ -21,9 +21,9 @@
#include "utils/memutils.h"
#include "utils/memdebug.h"
-int __attribute__((constructor)) Initialize(void) {
- FuzzerInitialize("json_db");
- return 0;
+int LLVMFuzzerInitialize(int *argc, char ***argv) {
+ FuzzerInitialize("json_db", argv);
+ return 0;
}
/*
diff --git a/projects/postgresql/fuzzer/simple_query_fuzzer.c b/projects/postgresql/fuzzer/simple_query_fuzzer.c
index 1749f089..3ba6b50e 100644
--- a/projects/postgresql/fuzzer/simple_query_fuzzer.c
+++ b/projects/postgresql/fuzzer/simple_query_fuzzer.c
@@ -35,7 +35,6 @@
#include "utils/snapmgr.h"
#include "utils/timeout.h"
-
static void
exec_simple_query(const char *query_string)
{
@@ -94,9 +93,9 @@ exec_simple_query(const char *query_string)
}
-int __attribute__((constructor)) Initialize(void) {
- FuzzerInitialize("query_db");
- return 0;
+int LLVMFuzzerInitialize(int *argc, char ***argv) {
+ FuzzerInitialize("query_db", argv);
+ return 0;
}