From 2e9c971eafb4cd7218f0711edd8a4de7320bad55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Bu=CC=88nemann?= Date: Tue, 15 Jul 2025 18:23:58 +0200 Subject: [PATCH] Fix pg_autoctl monitor bad memory access The current code in pg_autoctl/monitor.c causes a use-after-scope bad memory access because it assigns a pointer inside a block that is then used outside this scope. The fix is to move the initialization of the referenced value to the beginning of the function, outside the block scope. --- src/bin/pg_autoctl/monitor.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/pg_autoctl/monitor.c b/src/bin/pg_autoctl/monitor.c index 7afd5d2cc..9b7dd200c 100644 --- a/src/bin/pg_autoctl/monitor.c +++ b/src/bin/pg_autoctl/monitor.c @@ -371,13 +371,14 @@ monitor_get_nodes(Monitor *monitor, char *formation, int groupId, int paramCount = 1; Oid paramTypes[2] = { TEXTOID, INT4OID }; const char *paramValues[2] = { 0 }; + IntString myGroupIdString = { 0 }; NodeAddressArrayParseContext parseContext = { { 0 }, nodeArray, false }; paramValues[0] = formation; if (groupId > -1) { - IntString myGroupIdString = intToString(groupId); + myGroupIdString = intToString(groupId); ++paramCount; paramValues[1] = myGroupIdString.strValue; @@ -429,12 +430,13 @@ monitor_print_nodes_as_json(Monitor *monitor, char *formation, int groupId) int paramCount = 1; Oid paramTypes[2] = { TEXTOID, INT4OID }; const char *paramValues[2] = { 0 }; + IntString myGroupIdString = { 0 }; paramValues[0] = formation; if (groupId > -1) { - IntString myGroupIdString = intToString(groupId); + myGroupIdString = intToString(groupId); ++paramCount; paramValues[1] = myGroupIdString.strValue;