Skip to content

Commit 02e20bb

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 c829fbc commit 02e20bb

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

11031103
objDesc = getObjectDescription(obj, false);
11041104

1105+
/* An object being dropped concurrently doesn't need to be reported */
1106+
if (objDesc == NULL)
1107+
continue;
1108+
11051109
/*
11061110
* If, at any stage of the recursive search, we reached the object via
11071111
* an AUTO, INTERNAL, PARTITION, or EXTENSION dependency, then it's
@@ -1127,23 +1131,28 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
11271131
char *otherDesc = getObjectDescription(&extra->dependee,
11281132
false);
11291133

1130-
if (numReportedClient < MAX_REPORTED_DEPS)
1134+
if (otherDesc)
11311135
{
1136+
if (numReportedClient < MAX_REPORTED_DEPS)
1137+
{
1138+
/* separate entries with a newline */
1139+
if (clientdetail.len != 0)
1140+
appendStringInfoChar(&clientdetail, '\n');
1141+
appendStringInfo(&clientdetail, _("%s depends on %s"),
1142+
objDesc, otherDesc);
1143+
numReportedClient++;
1144+
}
1145+
else
1146+
numNotReportedClient++;
11321147
/* separate entries with a newline */
1133-
if (clientdetail.len != 0)
1134-
appendStringInfoChar(&clientdetail, '\n');
1135-
appendStringInfo(&clientdetail, _("%s depends on %s"),
1148+
if (logdetail.len != 0)
1149+
appendStringInfoChar(&logdetail, '\n');
1150+
appendStringInfo(&logdetail, _("%s depends on %s"),
11361151
objDesc, otherDesc);
1137-
numReportedClient++;
1152+
pfree(otherDesc);
11381153
}
11391154
else
11401155
numNotReportedClient++;
1141-
/* separate entries with a newline */
1142-
if (logdetail.len != 0)
1143-
appendStringInfoChar(&logdetail, '\n');
1144-
appendStringInfo(&logdetail, _("%s depends on %s"),
1145-
objDesc, otherDesc);
1146-
pfree(otherDesc);
11471156
ok = false;
11481157
}
11491158
else

src/backend/catalog/pg_shdepend.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,12 @@ storeObjectDescription(StringInfo descs,
12381238
{
12391239
char *objdesc = getObjectDescription(object, false);
12401240

1241+
/*
1242+
* An object being dropped concurrently doesn't need to be reported.
1243+
*/
1244+
if (objdesc == NULL)
1245+
return;
1246+
12411247
/* separate entries with a newline */
12421248
if (descs->len != 0)
12431249
appendStringInfoChar(descs, '\n');

0 commit comments

Comments
 (0)