From cd7d748d51df3c5dedcc49a3603e6fa9c050f237 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Wed, 2 Feb 2011 20:26:43 -0500
Subject: [PATCH] Repair multiple breakage in Windows-specific code for
 appending '.exe'.

---
 contrib/pg_upgrade/exec.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/contrib/pg_upgrade/exec.c b/contrib/pg_upgrade/exec.c
index 3ad9dbb1a28..7095ba62a80 100644
--- a/contrib/pg_upgrade/exec.c
+++ b/contrib/pg_upgrade/exec.c
@@ -186,16 +186,10 @@ validate_exec(const char *dir, const char *cmdName)
 	snprintf(path, sizeof(path), "%s/%s", dir, cmdName);
 
 #ifdef WIN32
-	/* Win32 requires a .exe suffix for stat() */
-	char		path_exe[MAXPGPATH + sizeof(EXE_EXT) - 1];
-
-	if (strlen(path) >= strlen(EXE_EXT) &&
+	/* Windows requires a .exe suffix for stat() */
+	if (strlen(path) <= strlen(EXE_EXT) ||
 		pg_strcasecmp(path + strlen(path) - strlen(EXE_EXT), EXE_EXT) != 0)
-	{
-		strcpy(path_exe, path);
-		strcat(path_exe, EXE_EXT);
-		path = path_exe;
-	}
+		strlcat(path, EXE_EXT, sizeof(path));
 #endif
 
 	/*
-- 
GitLab