From d31ff14ed871da4deff2f47486ebc0df3b1b6461 Mon Sep 17 00:00:00 2001
From: Tatsuo Ishii <ishii@postgresql.org>
Date: Fri, 10 Dec 1999 10:29:01 +0000
Subject: [PATCH] Fix memory overrun while setting ps status

---
 src/backend/utils/init/globals.c |  9 ++++++++-
 src/include/utils/ps_status.h    | 15 +++++++--------
 2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index cada72bb089..19d07dc7525 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.38 1999/10/08 04:28:48 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.39 1999/12/10 10:29:01 ishii Exp $
  *
  * NOTES
  *	  Globals used all over the place should be declared here and not
@@ -88,6 +88,13 @@ char	   *IndexedCatalogNames[] = {
 };
 
 
+/*
+ * ps status buffer
+ */
+#ifndef linux
+char	Ps_status_buffer[1024];
+#endif
+
 /* ----------------
  * we just do a linear search now so there's no requirement that the list
  * be ordered.	The list is so small it shouldn't make much difference.
diff --git a/src/include/utils/ps_status.h b/src/include/utils/ps_status.h
index bb7cb7bea36..014105b2c80 100644
--- a/src/include/utils/ps_status.h
+++ b/src/include/utils/ps_status.h
@@ -48,10 +48,9 @@ char *ps_status_buffer = NULL
 
 #else							/* !linux */
 
-extern const char **ps_status;
+extern char Ps_status_buffer[];
 
-#define PS_DEFINE_BUFFER \
-const char **ps_status = NULL
+#define PS_DEFINE_BUFFER
 
 #define PS_INIT_STATUS(argc, argv, execname, username, hostname, dbname) \
 	{ \
@@ -61,18 +60,18 @@ const char **ps_status = NULL
 		argv[1] = hostname; \
 		argv[2] = username; \
 		argv[3] = dbname; \
-		ps_status = (const char **)&argv[4]; \
-		for (i = 4; i < argc; i++) \
+		argv[4] = Ps_status_buffer; \
+		for (i = 5; i < argc; i++) \
 			argv[i] = "";  /* blank them */ \
 	}
 
 #define PS_CLEAR_STATUS() \
-	{ if (ps_status) *ps_status = ""; }
+	{ Ps_status_buffer[0] = '\0'; }
 
 #define PS_SET_STATUS(status) \
-	{ if (ps_status) *ps_status = (status); }
+	{ strcpy(Ps_status_buffer, (status)); }
 
-#define PS_STATUS (ps_status ? *ps_status : "")
+#define PS_STATUS (Ps_status_buffer)
 #endif
 
 #ifdef NO_PS_STATUS
-- 
GitLab