Skip to content

Commit 894fc6b

Browse files
committed
Fix aclexplode to not explode on a zero-entry ACL array.
(An Assert is no substitute for thinking clearly :-() Minor style kibitzing too. Per report from Robert Treat.
1 parent 6ce4e4f commit 894fc6b

File tree

1 file changed

+16
-14
lines changed
  • src/backend/utils/adt

1 file changed

+16
-14
lines changed

src/backend/utils/adt/acl.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.154 2010/01/02 16:57:53 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.155 2010/01/12 02:39:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1680,9 +1680,9 @@ convert_aclright_to_string(int aclright)
16801680
Datum
16811681
aclexplode(PG_FUNCTION_ARGS)
16821682
{
1683+
Acl *acl = PG_GETARG_ACL_P(0);
16831684
FuncCallContext *funcctx;
16841685
int *idx;
1685-
Acl *acl = PG_GETARG_ACL_P(0);
16861686
AclItem *aidat;
16871687

16881688
if (SRF_IS_FIRSTCALL())
@@ -1722,34 +1722,36 @@ aclexplode(PG_FUNCTION_ARGS)
17221722

17231723
funcctx = SRF_PERCALL_SETUP();
17241724
idx = (int *) funcctx->user_fctx;
1725-
17261725
aidat = ACL_DAT(acl);
1727-
while (1)
1726+
1727+
/* need test here in case acl has no items */
1728+
while (idx[0] < ACL_NUM(acl))
17281729
{
1730+
AclItem *aidata;
1731+
AclMode priv_bit;
1732+
17291733
idx[1]++;
17301734
if (idx[1] == N_ACL_RIGHTS)
17311735
{
17321736
idx[1] = 0;
17331737
idx[0]++;
1734-
if (idx[0] == ACL_NUM(acl))
1735-
/* done */
1738+
if (idx[0] >= ACL_NUM(acl)) /* done */
17361739
break;
17371740
}
1741+
aidata = &aidat[idx[0]];
1742+
priv_bit = 1 << idx[1];
17381743

1739-
Assert(idx[0] < ACL_NUM(acl));
1740-
Assert(idx[1] < N_ACL_RIGHTS);
1741-
1742-
if (ACLITEM_GET_PRIVS(aidat[idx[0]]) & (1 << idx[1]))
1744+
if (ACLITEM_GET_PRIVS(*aidata) & priv_bit)
17431745
{
17441746
Datum result;
17451747
Datum values[4];
17461748
bool nulls[4];
17471749
HeapTuple tuple;
17481750

1749-
values[0] = ObjectIdGetDatum(aidat[idx[0]].ai_grantor);
1750-
values[1] = ObjectIdGetDatum(aidat[idx[0]].ai_grantee);
1751-
values[2] = CStringGetTextDatum(convert_aclright_to_string(1 << idx[1]));
1752-
values[3] = BoolGetDatum(ACLITEM_GET_GOPTIONS(aidat[idx[0]]) & (1 << idx[1]));
1751+
values[0] = ObjectIdGetDatum(aidata->ai_grantor);
1752+
values[1] = ObjectIdGetDatum(aidata->ai_grantee);
1753+
values[2] = CStringGetTextDatum(convert_aclright_to_string(priv_bit));
1754+
values[3] = BoolGetDatum((ACLITEM_GET_GOPTIONS(*aidata) & priv_bit) != 0);
17531755

17541756
MemSet(nulls, 0, sizeof(nulls));
17551757

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy