From ae0f8ba0b886512f8e66e89ff794b5a28ded0b96 Mon Sep 17 00:00:00 2001
From: Emre Hasegeli <emre@hasegeli.com>
Date: Mon, 13 Mar 2023 16:54:18 +0100
Subject: [PATCH v00 1/2] pgoutput: Test if protocol_version is given

---
 src/backend/replication/pgoutput/pgoutput.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index f9ed1083df..f8aac22cfe 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -393,20 +393,30 @@ parse_output_parameters(List *options, PGOutputData *data)
 			else if (pg_strcasecmp(origin, LOGICALREP_ORIGIN_ANY) == 0)
 				data->publish_no_origin = false;
 			else
 				ereport(ERROR,
 						errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 						errmsg("unrecognized origin value: \"%s\"", origin));
 		}
 		else
 			elog(ERROR, "unrecognized pgoutput option: %s", defel->defname);
 	}
+
+	/* Check required parameters */
+	if (!protocol_version_given)
+		ereport(ERROR,
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				errmsg("proto_version parameter missing")));
+	if (!publication_names_given)
+		ereport(ERROR,
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+				errmsg("publication_names parameter missing")));
 }
 
 /*
  * Initialize this plugin
  */
 static void
 pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
 				 bool is_init)
 {
 	PGOutputData *data = palloc0(sizeof(PGOutputData));
@@ -442,25 +452,20 @@ pgoutput_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt,
 					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 					 errmsg("client sent proto_version=%d but server only supports protocol %d or lower",
 							data->protocol_version, LOGICALREP_PROTO_MAX_VERSION_NUM)));
 
 		if (data->protocol_version < LOGICALREP_PROTO_MIN_VERSION_NUM)
 			ereport(ERROR,
 					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
 					 errmsg("client sent proto_version=%d but server only supports protocol %d or higher",
 							data->protocol_version, LOGICALREP_PROTO_MIN_VERSION_NUM)));
 
-		if (data->publication_names == NIL)
-			ereport(ERROR,
-					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
-					 errmsg("publication_names parameter missing")));
-
 		/*
 		 * Decide whether to enable streaming. It is disabled by default, in
 		 * which case we just update the flag in decoding context. Otherwise
 		 * we only allow it with sufficient version of the protocol, and when
 		 * the output plugin supports it.
 		 */
 		if (data->streaming == LOGICALREP_STREAM_OFF)
 			ctx->streaming = false;
 		else if (data->streaming == LOGICALREP_STREAM_ON &&
 				 data->protocol_version < LOGICALREP_PROTO_STREAM_VERSION_NUM)
-- 
2.39.3 (Apple Git-145)

