From af7ef0f6bee545c3cd8519ca4678fbe93c6bfffe Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Fri, 8 Oct 2021 15:49:02 +0100 Subject: [PATCH] postgresql: fix build (#6570) * postgresql: fix build * update PostgresMain params * use PostgresSingle following updates in postgres * postgresql tmp fix * fix build --- projects/postgresql/add_fuzzers.diff | 29 ++++++++++---------- projects/postgresql/build.sh | 13 +++++---- projects/postgresql/fuzzer/protocol_fuzzer.c | 4 +-- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/projects/postgresql/add_fuzzers.diff b/projects/postgresql/add_fuzzers.diff index b7a47942c..5674bc34d 100644 --- a/projects/postgresql/add_fuzzers.diff +++ b/projects/postgresql/add_fuzzers.diff @@ -1,26 +1,27 @@ diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c -index 825fd55107..f3e2dbbf20 100644 +index 0775abe35d..f53b3580b3 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c -@@ -105,6 +105,10 @@ int PostAuthDelay = 0; +@@ -105,6 +105,11 @@ int PostAuthDelay = 0; /* Time between checks that the client is still connected. */ int client_connection_check_interval = 0; +#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION +bool fuzzer_first_run = true; +#endif ++ + /* ---------------- * private typedefs etc * ---------------- -@@ -454,10 +458,15 @@ ReadCommand(StringInfo inBuf) +@@ -471,11 +476,14 @@ static int + ReadCommand(StringInfo inBuf) { int result; - +- +#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -+ result = SocketBackend(inBuf); ++ result = SocketBackend(inBuf); +#else -+ if (whereToSendOutput == DestRemote) result = SocketBackend(inBuf); else @@ -29,19 +30,19 @@ index 825fd55107..f3e2dbbf20 100644 return result; } -@@ -3910,6 +3919,11 @@ PostgresMain(int argc, char *argv[], +@@ -4021,6 +4029,11 @@ PostgresMain(const char *dbname, const char *username) bool idle_in_transaction_timeout_enabled = false; bool idle_session_timeout_enabled = false; +#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION -+ if(fuzzer_first_run) -+ { ++ if(fuzzer_first_run) ++ { +#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ + - /* Initialize startup process environment if necessary. */ - if (!IsUnderPostmaster) - InitStandaloneProcess(argv[0]); -@@ -4271,6 +4285,11 @@ PostgresMain(int argc, char *argv[], + AssertArg(dbname != NULL); + AssertArg(username != NULL); + +@@ -4312,6 +4325,11 @@ PostgresMain(const char *dbname, const char *username) if (!ignore_till_sync) send_ready_for_query = true; /* initially, or after error */ @@ -54,7 +55,7 @@ index 825fd55107..f3e2dbbf20 100644 * Non-error queries loop here. */ diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c -index a1ebe06d5b..dfa94013a0 100644 +index 2af87ee3bd..825bb70532 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -594,7 +594,9 @@ errfinish(const char *filename, int lineno, const char *funcname) diff --git a/projects/postgresql/build.sh b/projects/postgresql/build.sh index 4e001ad0e..ee56ecdef 100644 --- a/projects/postgresql/build.sh +++ b/projects/postgresql/build.sh @@ -15,7 +15,7 @@ # ################################################################################ cp -r $SRC/fuzzer src/backend/ -git apply ../add_fuzzers.diff +git apply --ignore-space-change --ignore-whitespace ../add_fuzzers.diff useradd fuzzuser chown -R fuzzuser . @@ -35,9 +35,12 @@ make clean make cd src/backend/fuzzer make fuzzer -if [ "$FUZZING_ENGINE" = "afl" ] -then - rm protocol_fuzzer -fi +#if [ "$FUZZING_ENGINE" = "afl" ] +#then +rm protocol_fuzzer +#fi cp *_fuzzer $OUT/ cp $SRC/postgresql_fuzzer_seed_corpus.zip $OUT/ + +# Temporary fix. Todo: David fix this. +#rm $OUT/protocol_fuzzer diff --git a/projects/postgresql/fuzzer/protocol_fuzzer.c b/projects/postgresql/fuzzer/protocol_fuzzer.c index 7621644f7..3efe8e4b2 100644 --- a/projects/postgresql/fuzzer/protocol_fuzzer.c +++ b/projects/postgresql/fuzzer/protocol_fuzzer.c @@ -74,7 +74,7 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) { MemoryContextInit(); if(!sigsetjmp(postgre_exit, 0)){ postgre_started = true; - PostgresMain(5, av, "dbfuzz", "fuzzuser"); + PostgresSingleUserMain(5, av, "fuzzuser"); } pq_endmsgread(); return 0; @@ -106,7 +106,7 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if(!sigsetjmp(postgre_exit, 0)){ postgre_started = true; - PostgresMain(5, av, "dbfuzz", "fuzzuser"); + PostgresSingleUserMain(5, av, "fuzzuser"); } pq_endmsgread(); postgre_started = false;