From 175f52083b4185177d2571904d974d52686ef01a Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Tue, 28 Nov 2000 23:42:31 +0000
Subject: [PATCH] aclitemout() shouldn't coredump when it finds an ACL item for
 a now-vanished group.  Instead, display the numeric group ID, same as it does
 for vanished users.

---
 src/backend/catalog/aclchk.c |  7 ++++---
 src/backend/utils/adt/acl.c  | 31 +++++++++++++++++++++----------
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index b2698ad19b6..67f675f0d3b 100644
--- a/src/backend/catalog/aclchk.c
+++ b/src/backend/catalog/aclchk.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.43 2000/11/16 22:30:17 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.44 2000/11/28 23:42:31 tgl Exp $
  *
  * NOTES
  *	  See acl.h.
@@ -172,6 +172,9 @@ get_grosysid(char *groname)
 	return id;
 }
 
+/*
+ * Convert group ID to name, or return NULL if group can't be found
+ */
 char *
 get_groname(AclId grosysid)
 {
@@ -186,8 +189,6 @@ get_groname(AclId grosysid)
 		name = pstrdup(NameStr(((Form_pg_group) GETSTRUCT(tuple))->groname));
 		ReleaseSysCache(tuple);
 	}
-	else
-		elog(NOTICE, "get_groname: group %u not found", grosysid);
 	return name;
 }
 
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index a8bc5e349a3..ee3a41701f7 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.53 2000/11/16 22:30:31 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.54 2000/11/28 23:42:31 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -276,7 +276,14 @@ aclitemout(PG_FUNCTION_ARGS)
 			htup = SearchSysCache(SHADOWSYSID,
 								  ObjectIdGetDatum(aip->ai_id),
 								  0, 0, 0);
-			if (!HeapTupleIsValid(htup))
+			if (HeapTupleIsValid(htup))
+			{
+				strncat(p,
+						NameStr(((Form_pg_shadow) GETSTRUCT(htup))->usename),
+						NAMEDATALEN);
+				ReleaseSysCache(htup);
+			}
+			else
 			{
 				/* Generate numeric UID if we don't find an entry */
 				char	   *tmp;
@@ -286,18 +293,22 @@ aclitemout(PG_FUNCTION_ARGS)
 				strcat(p, tmp);
 				pfree(tmp);
 			}
-			else
-			{
-				strncat(p, (char *) &((Form_pg_shadow)
-									  GETSTRUCT(htup))->usename,
-						sizeof(NameData));
-				ReleaseSysCache(htup);
-			}
 			break;
 		case ACL_IDTYPE_GID:
 			strcat(p, "group ");
 			tmpname = get_groname(aip->ai_id);
-			strncat(p, tmpname, NAMEDATALEN);
+			if (tmpname != NULL)
+				strncat(p, tmpname, NAMEDATALEN);
+			else
+			{
+				/* Generate numeric GID if we don't find an entry */
+				char	   *tmp;
+
+				tmp = DatumGetCString(DirectFunctionCall1(int4out,
+									  Int32GetDatum((int32) aip->ai_id)));
+				strcat(p, tmp);
+				pfree(tmp);
+			}
 			break;
 		case ACL_IDTYPE_WORLD:
 			break;
-- 
GitLab