Skip to content

Commit 92224e4

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 b110af5 commit 92224e4

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
@@ -910,6 +910,10 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
910910

911911
objDesc = getObjectDescription(obj);
912912

913+
/* An object being dropped concurrently doesn't need to be reported */
914+
if (objDesc == NULL)
915+
continue;
916+
913917
/*
914918
* If, at any stage of the recursive search, we reached the object via
915919
* an AUTO, INTERNAL, or EXTENSION dependency, then it's okay to
@@ -933,23 +937,28 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
933937
{
934938
char *otherDesc = getObjectDescription(&extra->dependee);
935939

936-
if (numReportedClient < MAX_REPORTED_DEPS)
940+
if (otherDesc)
937941
{
942+
if (numReportedClient < MAX_REPORTED_DEPS)
943+
{
944+
/* separate entries with a newline */
945+
if (clientdetail.len != 0)
946+
appendStringInfoChar(&clientdetail, '\n');
947+
appendStringInfo(&clientdetail, _("%s depends on %s"),
948+
objDesc, otherDesc);
949+
numReportedClient++;
950+
}
951+
else
952+
numNotReportedClient++;
938953
/* separate entries with a newline */
939-
if (clientdetail.len != 0)
940-
appendStringInfoChar(&clientdetail, '\n');
941-
appendStringInfo(&clientdetail, _("%s depends on %s"),
954+
if (logdetail.len != 0)
955+
appendStringInfoChar(&logdetail, '\n');
956+
appendStringInfo(&logdetail, _("%s depends on %s"),
942957
objDesc, otherDesc);
943-
numReportedClient++;
958+
pfree(otherDesc);
944959
}
945960
else
946961
numNotReportedClient++;
947-
/* separate entries with a newline */
948-
if (logdetail.len != 0)
949-
appendStringInfoChar(&logdetail, '\n');
950-
appendStringInfo(&logdetail, _("%s depends on %s"),
951-
objDesc, otherDesc);
952-
pfree(otherDesc);
953962
ok = false;
954963
}
955964
else

src/backend/catalog/pg_shdepend.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,12 @@ storeObjectDescription(StringInfo descs,
11131113
{
11141114
char *objdesc = getObjectDescription(object);
11151115

1116+
/*
1117+
* An object being dropped concurrently doesn't need to be reported.
1118+
*/
1119+
if (objdesc == NULL)
1120+
return;
1121+
11161122
/* separate entries with a newline */
11171123
if (descs->len != 0)
11181124
appendStringInfoChar(descs, '\n');

0 commit comments

Comments
 (0)