oss-fuzz/projects/postgresql/add_fuzzers.diff

69 lines
2.0 KiB
Diff

diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index cb5a96117f..c9b4880085 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -102,6 +102,9 @@ int max_stack_depth = 100;
/* wait N seconds to allow attach from a debugger */
int PostAuthDelay = 0;
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+bool fuzzer_first_run = true;
+#endif
/* ----------------
@@ -507,10 +510,15 @@ ReadCommand(StringInfo inBuf)
{
int result;
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ result = SocketBackend(inBuf);
+#else
+
if (whereToSendOutput == DestRemote)
result = SocketBackend(inBuf);
else
result = InteractiveBackend(inBuf);
+#endif
return result;
}
@@ -3846,6 +3854,11 @@ PostgresMain(int argc, char *argv[],
bool idle_in_transaction_timeout_enabled = false;
bool idle_session_timeout_enabled = false;
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ if(fuzzer_first_run)
+ {
+#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
+
/* Initialize startup process environment if necessary. */
if (!IsUnderPostmaster)
InitStandaloneProcess(argv[0]);
@@ -4207,6 +4220,11 @@ PostgresMain(int argc, char *argv[],
if (!ignore_till_sync)
send_ready_for_query = true; /* initially, or after error */
+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
+ fuzzer_first_run=false;
+ }
+#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */
+
/*
* Non-error queries loop here.
*/
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 80c2672461..c16e0423c5 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -600,7 +600,9 @@ errfinish(const char *filename, int lineno, const char *funcname)
pq_endcopyout(true);
/* Emit the message to the right places */
+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
EmitErrorReport();
+#endif
/* Now free up subsidiary data attached to stack entry, and release it */
if (edata->message)