Skip to content

Commit 58b600f

Browse files
committed
Avoid crash in rare case of concurrent DROP
When a role being dropped contains is referenced by catalog objects that are concurrently also being dropped, a crash can result while trying to construct the string that describes the objects. Suppress that by ignoring objects whose descriptions are returned as NULL. The majority of relevant codesites were already cautious about this already; we had just missed a couple. This is an old bug, so backpatch all the way back. Reported-by: Alexander Lakhin <exclusion@gmail.com> Discussion: https://postgr.es/m/17126-21887f04508cb5c8@postgresql.org
1 parent 245799d commit 58b600f

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/backend/catalog/dependency.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,10 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
902902

903903
objDesc = getObjectDescription(obj);
904904

905+
/* An object being dropped concurrently doesn't need to be reported */
906+
if (objDesc == NULL)
907+
continue;
908+
905909
/*
906910
* If, at any stage of the recursive search, we reached the object via
907911
* an AUTO, INTERNAL, or EXTENSION dependency, then it's okay to
@@ -925,23 +929,28 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
925929
{
926930
char *otherDesc = getObjectDescription(&extra->dependee);
927931

928-
if (numReportedClient < MAX_REPORTED_DEPS)
932+
if (otherDesc)
929933
{
934+
if (numReportedClient < MAX_REPORTED_DEPS)
935+
{
936+
/* separate entries with a newline */
937+
if (clientdetail.len != 0)
938+
appendStringInfoChar(&clientdetail, '\n');
939+
appendStringInfo(&clientdetail, _("%s depends on %s"),
940+
objDesc, otherDesc);
941+
numReportedClient++;
942+
}
943+
else
944+
numNotReportedClient++;
930945
/* separate entries with a newline */
931-
if (clientdetail.len != 0)
932-
appendStringInfoChar(&clientdetail, '\n');
933-
appendStringInfo(&clientdetail, _("%s depends on %s"),
946+
if (logdetail.len != 0)
947+
appendStringInfoChar(&logdetail, '\n');
948+
appendStringInfo(&logdetail, _("%s depends on %s"),
934949
objDesc, otherDesc);
935-
numReportedClient++;
950+
pfree(otherDesc);
936951
}
937952
else
938953
numNotReportedClient++;
939-
/* separate entries with a newline */
940-
if (logdetail.len != 0)
941-
appendStringInfoChar(&logdetail, '\n');
942-
appendStringInfo(&logdetail, _("%s depends on %s"),
943-
objDesc, otherDesc);
944-
pfree(otherDesc);
945954
ok = false;
946955
}
947956
else

src/backend/catalog/pg_shdepend.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,12 @@ storeObjectDescription(StringInfo descs,
10651065
{
10661066
char *objdesc = getObjectDescription(object);
10671067

1068+
/*
1069+
* An object being dropped concurrently doesn't need to be reported.
1070+
*/
1071+
if (objdesc == NULL)
1072+
return;
1073+
10681074
/* separate entries with a newline */
10691075
if (descs->len != 0)
10701076
appendStringInfoChar(descs, '\n');

0 commit comments

Comments
 (0)