From 896a42a5a75b6fdd63f94e31f8ea970440d7b785 Mon Sep 17 00:00:00 2001
From: "Marc G. Fournier" <scrappy@hub.org>
Date: Wed, 1 Apr 1998 15:35:33 +0000
Subject: [PATCH] From: Maurice Gittens <mgittens@david.gits.nl>

After applying the following patch there remain two
probable buffer overruns detected by Electric Fence during
the regression test.
I'll try find out what causes the remain two ones.

This patch also corrects a typo in smgr.c.
---
 src/backend/catalog/pg_aggregate.c |  6 ++++--
 src/backend/catalog/pg_operator.c  | 11 ++++++++---
 src/backend/catalog/pg_proc.c      |  6 ++++--
 src/backend/catalog/pg_type.c      | 10 +++++-----
 src/backend/storage/smgr/smgr.c    |  4 ++--
 5 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/backend/catalog/pg_aggregate.c b/src/backend/catalog/pg_aggregate.c
index 84515e70edb..1a650b3d971 100644
--- a/src/backend/catalog/pg_aggregate.c
+++ b/src/backend/catalog/pg_aggregate.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.13 1998/02/26 04:30:40 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.14 1998/04/01 15:35:01 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -78,6 +78,7 @@ AggregateCreate(char *aggName,
 	Oid			xret2 = InvalidOid;
 	Oid			fret = InvalidOid;
 	Oid			fnArgs[8];
+	NameData		aname;
 	TupleDesc	tupDesc;
 
 	MemSet(fnArgs, 0, 8 * sizeof(Oid));
@@ -202,7 +203,8 @@ AggregateCreate(char *aggName,
 		nulls[i] = ' ';
 		values[i] = (Datum) NULL;
 	}
-	values[Anum_pg_aggregate_aggname - 1] = PointerGetDatum(aggName);
+	namestrcpy(&aname, aggName);
+	values[Anum_pg_aggregate_aggname - 1] = NameGetDatum(&aname);
 	values[Anum_pg_aggregate_aggowner - 1] =
 		Int32GetDatum(GetUserId());
 	values[Anum_pg_aggregate_aggtransfn1 - 1] =
diff --git a/src/backend/catalog/pg_operator.c b/src/backend/catalog/pg_operator.c
index fc251274277..1529afabab5 100644
--- a/src/backend/catalog/pg_operator.c
+++ b/src/backend/catalog/pg_operator.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.22 1998/02/26 04:30:41 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.23 1998/04/01 15:35:04 scrappy Exp $
  *
  * NOTES
  *	  these routines moved here from commands/define.c and somewhat cleaned up.
@@ -19,6 +19,7 @@
 #include <catalog/pg_proc.h>
 #include <utils/syscache.h>
 #include <utils/tqual.h>
+#include <utils/builtins.h>
 #include <access/heapam.h>
 #include <catalog/catname.h>
 #include <catalog/pg_operator.h>
@@ -229,6 +230,7 @@ OperatorShellMakeWithOpenRelation(Relation pg_operator_desc,
 	Datum		values[Natts_pg_operator];
 	char		nulls[Natts_pg_operator];
 	Oid			operatorObjectId;
+	NameData	oname;
 	TupleDesc	tupDesc;
 
 	/* ----------------
@@ -246,7 +248,8 @@ OperatorShellMakeWithOpenRelation(Relation pg_operator_desc,
 	 * ----------------
 	 */
 	i = 0;
-	values[i++] = PointerGetDatum(operatorName);
+	namestrcpy(&oname, operatorName);
+	values[i++] = NameGetDatum(&oname);
 	values[i++] = Int32GetDatum(GetUserId());
 	values[i++] = (Datum) (uint16) 0;
 
@@ -474,6 +477,7 @@ OperatorDef(char *operatorName,
 	char	   *name[4];
 	Oid			typeId[8];
 	int			nargs;
+	NameData		oname;
 	TupleDesc	tupDesc;
 
 	static ScanKeyData opKey[3] = {
@@ -608,7 +612,8 @@ OperatorDef(char *operatorName,
 	 * ----------------
 	 */
 	i = 0;
-	values[i++] = PointerGetDatum(operatorName);
+	namestrcpy(&oname, operatorName);
+	values[i++] = NameGetDatum(&oname);
 	values[i++] = Int32GetDatum(GetUserId());
 	values[i++] = UInt16GetDatum(precedence);
 	values[i++] = leftTypeName ? (rightTypeName ? 'b' : 'r') : 'l';
diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c
index f300b97965d..5eaa5833ab9 100644
--- a/src/backend/catalog/pg_proc.c
+++ b/src/backend/catalog/pg_proc.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.15 1998/02/26 04:30:43 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.16 1998/04/01 15:35:05 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -71,6 +71,7 @@ ProcedureCreate(char *procedureName,
 	Oid			relid;
 	Oid			toid;
 	text	   *prosrctext;
+	NameData	procname;
 	TupleDesc	tupDesc;
 
 	/* ----------------
@@ -229,7 +230,8 @@ ProcedureCreate(char *procedureName,
 	}
 
 	i = 0;
-	values[i++] = PointerGetDatum(procedureName);
+	namestrcpy(&procname, procedureName);
+	values[i++] = NameGetDatum(&procname);
 	values[i++] = Int32GetDatum(GetUserId());
 	values[i++] = ObjectIdGetDatum(languageObjectId);
 
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c
index 2ca77f29926..d08e44a8eeb 100644
--- a/src/backend/catalog/pg_type.c
+++ b/src/backend/catalog/pg_type.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.21 1998/03/30 17:46:45 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.22 1998/04/01 15:35:08 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -160,6 +160,7 @@ TypeShellMakeWithOpenRelation(Relation pg_type_desc, char *typeName)
 	Datum		values[Natts_pg_type];
 	char		nulls[Natts_pg_type];
 	Oid			typoid;
+	NameData	name;
 	TupleDesc	tupDesc;
 
 	/* ----------------
@@ -177,7 +178,8 @@ TypeShellMakeWithOpenRelation(Relation pg_type_desc, char *typeName)
 	 * ----------------
 	 */
 	i = 0;
-	values[i++] = (Datum) typeName;		/* 1 */
+	namestrcpy(&name, typeName);
+	values[i++] = NameGetDatum(&name);		/* 1 */
 	values[i++] = (Datum) InvalidOid;	/* 2 */
 	values[i++] = (Datum) (int16) 0;	/* 3 */
 	values[i++] = (Datum) (int16) 0;	/* 4 */
@@ -315,11 +317,9 @@ TypeCreate(char *typeName,
 	char	   *procs[4];
 	bool		defined;
 	ItemPointerData itemPointerData;
+	NameData	name;
 	TupleDesc	tupDesc;
-
 	Oid			argList[8];
-	NameData	 	name;
-
 
 	static ScanKeyData typeKey[1] = {
 		{0, Anum_pg_type_typname, NameEqualRegProcedure}
diff --git a/src/backend/storage/smgr/smgr.c b/src/backend/storage/smgr/smgr.c
index e7f9d2d8311..c6956b30999 100644
--- a/src/backend/storage/smgr/smgr.c
+++ b/src/backend/storage/smgr/smgr.c
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.13 1998/01/07 21:05:45 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/smgr/smgr.c,v 1.14 1998/04/01 15:35:33 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -132,7 +132,7 @@ smgrcreate(int16 which, Relation reln)
 	int			fd;
 
 	if ((fd = (*(smgrsw[which].smgr_create)) (reln)) < 0)
-		elog(ERROR, "cannot open %s",
+		elog(ERROR, "cannot create %s",
 			 &(reln->rd_rel->relname.data[0]));
 
 	return (fd);
-- 
GitLab