From b7d49a420949f17a76206ea74b8fa30e45e19a7b Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Mon, 18 Oct 1999 03:32:29 +0000
Subject: [PATCH] Drive a stake through the heart of the last use of
 MAX_PARSE_BUFFER in the backend.  Still a few stragglers, but we're getting
 closer to being rid of query length limits...

---
 src/backend/utils/adt/acl.c | 46 ++++++++++++++++++++-----------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index c3fa3396ef6..3793c749b9c 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -7,17 +7,18 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.40 1999/07/17 20:17:52 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/acl.c,v 1.41 1999/10/18 03:32:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include <ctype.h>
+
 #include "postgres.h"
 
 #include "catalog/catalog.h"
 #include "catalog/pg_shadow.h"
 #include "catalog/pg_type.h"
-#include "miscadmin.h"
+#include "lib/stringinfo.h"
 #include "utils/acl.h"
 #include "utils/memutils.h"
 #include "utils/syscache.h"
@@ -41,7 +42,7 @@ static char *aclparse(char *s, AclItem *aip, unsigned *modechg);
  *		the string position in 's' that points to the next non-space character
  *		in 's', after any quotes.  Also:
  *		- loads the identifier into 'name'.  (If no identifier is found, 'name'
- *		  contains an empty string).
+ *		  contains an empty string.)  name must be NAMEDATALEN bytes.
  */
 static char *
 getid(char *s, char *n)
@@ -69,9 +70,9 @@ getid(char *s, char *n)
 			in_quotes = 0;
 		}
 	}
-	if (len > sizeof(NameData))
-		elog(ERROR, "getid: identifier cannot be >%d characters",
-			 sizeof(NameData));
+	if (len >= NAMEDATALEN)
+		elog(ERROR, "getid: identifier must be <%d characters",
+			 NAMEDATALEN);
 	if (len > 0)
 		memmove(n, id, len);
 	n[len] = '\0';
@@ -205,10 +206,10 @@ makeacl(int n)
 	Size		size;
 
 	if (n < 0)
-		elog(ERROR, "makeacl: invalid size: %d\n", n);
+		elog(ERROR, "makeacl: invalid size: %d", n);
 	size = ACL_N_SIZE(n);
 	if (!(new_acl = (Acl *) palloc(size)))
-		elog(ERROR, "makeacl: palloc failed on %d\n", size);
+		elog(ERROR, "makeacl: palloc failed on %d", size);
 	MemSet((char *) new_acl, 0, size);
 	new_acl->size = size;
 	new_acl->ndim = 1;
@@ -679,34 +680,37 @@ ChangeACLStmt *
 makeAclStmt(char *privileges, List *rel_list, char *grantee,
 			char grant_or_revoke)
 {
-	ChangeACLStmt *n = makeNode(ChangeACLStmt);
-	char		str[MAX_PARSE_BUFFER];
+	ChangeACLStmt  *n = makeNode(ChangeACLStmt);
+	StringInfoData	str;
+
+	initStringInfo(&str);
 
 	/* see comment in pg_type.h */
 	Assert(ACLITEMSIZE == sizeof(AclItem));
 
 	n->aclitem = (AclItem *) palloc(sizeof(AclItem));
 
-	/* the grantee string is "G <group_name>", "U  <user_name>", or "ALL" */
+	/* the grantee string is "G <group_name>", "U <user_name>", or "ALL" */
 	if (grantee[0] == 'G')		/* group permissions */
 	{
-		sprintf(str, "%s %c%s%c%c%s",
-				ACL_IDTYPE_GID_KEYWORD,
-				'"', grantee + 2, '"', grant_or_revoke, privileges);
+		appendStringInfo(&str, "%s \"%s\"%c%s",
+						 ACL_IDTYPE_GID_KEYWORD,
+						 grantee + 2, grant_or_revoke, privileges);
 	}
 	else if (grantee[0] == 'U') /* user permission */
 	{
-		sprintf(str, "%s %c%s%c%c%s",
-				ACL_IDTYPE_UID_KEYWORD,
-				'"', grantee + 2, '"', grant_or_revoke, privileges);
+		appendStringInfo(&str, "%s \"%s\"%c%s",
+						 ACL_IDTYPE_UID_KEYWORD,
+						 grantee + 2, grant_or_revoke, privileges);
 	}
 	else
-/* all permission */
 	{
-		sprintf(str, "%c%s",
-				grant_or_revoke, privileges);
+		/* all permission */
+		appendStringInfo(&str, "%c%s",
+						 grant_or_revoke, privileges);
 	}
 	n->relNames = rel_list;
-	aclparse(str, n->aclitem, (unsigned *) &n->modechg);
+	aclparse(str.data, n->aclitem, (unsigned *) &n->modechg);
+	pfree(str.data);
 	return n;
 }
-- 
GitLab