From e04e7b44ab423e37378c4dbfff439e53089994ec Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Thu, 10 Nov 2022 02:05:42 +0100 Subject: [PATCH] postgresql: fix build (#8963) Ref: https://github.com/google/oss-fuzz/pull/8948 Signed-off-by: David Korczynski Signed-off-by: David Korczynski --- projects/postgresql/add_fuzzers.diff | 4 ++-- projects/postgresql/fuzzer/Makefile | 6 +++--- projects/postgresql/fuzzer/fuzzer_initialize.c | 2 +- projects/postgresql/fuzzer/simple_query_fuzzer.c | 3 +-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/projects/postgresql/add_fuzzers.diff b/projects/postgresql/add_fuzzers.diff index 5674bc34d..14f1aa8ea 100644 --- a/projects/postgresql/add_fuzzers.diff +++ b/projects/postgresql/add_fuzzers.diff @@ -39,8 +39,8 @@ index 0775abe35d..f53b3580b3 100644 + { +#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ + - AssertArg(dbname != NULL); - AssertArg(username != NULL); + Assert(dbname != NULL); + Assert(username != NULL); @@ -4312,6 +4325,11 @@ PostgresMain(const char *dbname, const char *username) if (!ignore_till_sync) diff --git a/projects/postgresql/fuzzer/Makefile b/projects/postgresql/fuzzer/Makefile index 656b8d69c..35d389166 100644 --- a/projects/postgresql/fuzzer/Makefile +++ b/projects/postgresql/fuzzer/Makefile @@ -22,7 +22,7 @@ objfiles.txt: Makefile $(SUBDIROBJS) $(OBJS_FUZZERS) SUBDIRS = ../access ../bootstrap ../catalog ../parser ../commands ../executor ../foreign ../lib ../libpq \ ../main ../nodes ../optimizer ../partitioning ../port ../postmaster \ - ../regex ../replication ../rewrite \ + ../regex ../replication ../rewrite ../backup \ ../statistics ../storage ../tcop ../tsearch ../utils $(top_builddir)/src/timezone \ ../jit @@ -41,13 +41,13 @@ fuzzer: simple_query_fuzzer \ protocol_fuzzer simple_query_fuzzer json_parser_fuzzer: %: %.o fuzzer_initialize.o $(OBJS_FUZZERS) - $(CXX) $(CFLAGS) $(call expand_subsys,$^) -o $@ $(LIB_FUZZING_ENGINE) + $(CXX) $(CFLAGS) $(call expand_subsys,$^) -o $@ $(LIB_FUZZING_ENGINE) -lz simple_query_fuzzer.o json_parser_fuzzer.o protocol_fuzzer.o fuzzer_initialize.o: %.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $^ protocol_fuzzer: %: %.o $(OBJS_FUZZERS) - $(CXX) $(CFLAGS) $(call expand_subsys,$^) -o $@ $(LIB_FUZZING_ENGINE) -Wl,--wrap=exit -Wl,--wrap=pq_getbyte + $(CXX) $(CFLAGS) $(call expand_subsys,$^) -o $@ $(LIB_FUZZING_ENGINE) -Wl,--wrap=exit -Wl,--wrap=pq_getbyte -lz dbfuzz: dbfuzz.o | submake-libpgport temp-install $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@ \ diff --git a/projects/postgresql/fuzzer/fuzzer_initialize.c b/projects/postgresql/fuzzer/fuzzer_initialize.c index 33f8278b9..e6e8b80cf 100644 --- a/projects/postgresql/fuzzer/fuzzer_initialize.c +++ b/projects/postgresql/fuzzer/fuzzer_initialize.c @@ -86,7 +86,7 @@ int FuzzerInitialize(char *dbname, char ***argv){ InitProcess(); BaseInit(); PG_SETMASK(&UnBlockSig); - InitPostgres("dbfuzz", InvalidOid, username, InvalidOid, NULL, false); + InitPostgres("dbfuzz", InvalidOid, username, InvalidOid, false, false, NULL); SetProcessingMode(NormalProcessing); diff --git a/projects/postgresql/fuzzer/simple_query_fuzzer.c b/projects/postgresql/fuzzer/simple_query_fuzzer.c index 29c13623e..15474d567 100644 --- a/projects/postgresql/fuzzer/simple_query_fuzzer.c +++ b/projects/postgresql/fuzzer/simple_query_fuzzer.c @@ -79,7 +79,7 @@ exec_simple_query(const char *query_string) else oldcontext = MemoryContextSwitchTo(MessageContext); - querytree_list = pg_analyze_and_rewrite(parsetree, query_string, + querytree_list = pg_analyze_and_rewrite_fixedparams(parsetree, query_string, NULL, 0, NULL); plantree_list = pg_plan_queries(querytree_list, query_string, @@ -124,7 +124,6 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { AbortCurrentTransaction(); PortalErrorCleanup(); - SPICleanup(); jit_reset_after_error();