1diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c 2index cb5a96117f..c9b4880085 100644 3--- a/src/backend/tcop/postgres.c 4+++ b/src/backend/tcop/postgres.c 5@@ -102,6 +102,9 @@ int max_stack_depth = 100; 6 /* wait N seconds to allow attach from a debugger */ 7 int PostAuthDelay = 0; 8 9+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 10+bool fuzzer_first_run = true; 11+#endif 12 13 14 /* ---------------- 15@@ -507,10 +510,15 @@ ReadCommand(StringInfo inBuf) 16 { 17 int result; 18 19+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 20+ result = SocketBackend(inBuf); 21+#else 22+ 23 if (whereToSendOutput == DestRemote) 24 result = SocketBackend(inBuf); 25 else 26 result = InteractiveBackend(inBuf); 27+#endif 28 return result; 29 } 30 31@@ -3846,6 +3854,11 @@ PostgresMain(int argc, char *argv[], 32 bool idle_in_transaction_timeout_enabled = false; 33 bool idle_session_timeout_enabled = false; 34 35+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 36+ if(fuzzer_first_run) 37+ { 38+#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ 39+ 40 /* Initialize startup process environment if necessary. */ 41 if (!IsUnderPostmaster) 42 InitStandaloneProcess(argv[0]); 43@@ -4207,6 +4220,11 @@ PostgresMain(int argc, char *argv[], 44 if (!ignore_till_sync) 45 send_ready_for_query = true; /* initially, or after error */ 46 47+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 48+ fuzzer_first_run=false; 49+ } 50+#endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ 51+ 52 /* 53 * Non-error queries loop here. 54 */ 55diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c 56index 80c2672461..c16e0423c5 100644 57--- a/src/backend/utils/error/elog.c 58+++ b/src/backend/utils/error/elog.c 59@@ -600,7 +600,9 @@ errfinish(const char *filename, int lineno, const char *funcname) 60 pq_endcopyout(true); 61 62 /* Emit the message to the right places */ 63+#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 64 EmitErrorReport(); 65+#endif 66 67 /* Now free up subsidiary data attached to stack entry, and release it */ 68 if (edata->message) 69