From a9ec25c45e5fc9cc99a3a205c5490172fa16e097 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Thu, 24 Jul 2025 13:30:43 -0400
Subject: [PATCH v1] Avoid throwing away the error message in syncrep_yyerror.

Commit 473a575e05979b4dbb28b3f2544f4ec8f184ce65 purported to make this
function stash the error message in *syncrep_parse_result_p, but
it didn't actually.

As a result, an attempt to set synchronous_standby_names to any value
that does not parse resulted in a generic "parser failed." message
rather than anything more specific. This fixes that.
---
 src/backend/replication/syncrep_scanner.l | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/backend/replication/syncrep_scanner.l b/src/backend/replication/syncrep_scanner.l
index 7dec1f869c7..02004d621e7 100644
--- a/src/backend/replication/syncrep_scanner.l
+++ b/src/backend/replication/syncrep_scanner.l
@@ -157,17 +157,16 @@ syncrep_yyerror(SyncRepConfigData **syncrep_parse_result_p, char **syncrep_parse
 {
 	struct yyguts_t *yyg = (struct yyguts_t *) yyscanner;	/* needed for yytext
 															 * macro */
-	char *syncrep_parse_error_msg = *syncrep_parse_error_msg_p;
 
 	/* report only the first error in a parse operation */
-	if (syncrep_parse_error_msg)
+	if (*syncrep_parse_error_msg_p)
 		return;
 	if (yytext[0])
-		syncrep_parse_error_msg = psprintf("%s at or near \"%s\"",
-										   message, yytext);
+		*syncrep_parse_error_msg_p = psprintf("%s at or near \"%s\"",
+											  message, yytext);
 	else
-		syncrep_parse_error_msg = psprintf("%s at end of input",
-										   message);
+		*syncrep_parse_error_msg_p = psprintf("%s at end of input",
+											  message);
 }
 
 void
-- 
2.39.5 (Apple Git-154)

