Skip to content

Commit bf5cdcf

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 b7299b6 commit bf5cdcf

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

11101110
objDesc = getObjectDescription(obj);
11111111

1112+
/* An object being dropped concurrently doesn't need to be reported */
1113+
if (objDesc == NULL)
1114+
continue;
1115+
11121116
/*
11131117
* If, at any stage of the recursive search, we reached the object via
11141118
* an AUTO, INTERNAL, PARTITION, or EXTENSION dependency, then it's
@@ -1133,23 +1137,28 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
11331137
{
11341138
char *otherDesc = getObjectDescription(&extra->dependee);
11351139

1136-
if (numReportedClient < MAX_REPORTED_DEPS)
1140+
if (otherDesc)
11371141
{
1142+
if (numReportedClient < MAX_REPORTED_DEPS)
1143+
{
1144+
/* separate entries with a newline */
1145+
if (clientdetail.len != 0)
1146+
appendStringInfoChar(&clientdetail, '\n');
1147+
appendStringInfo(&clientdetail, _("%s depends on %s"),
1148+
objDesc, otherDesc);
1149+
numReportedClient++;
1150+
}
1151+
else
1152+
numNotReportedClient++;
11381153
/* separate entries with a newline */
1139-
if (clientdetail.len != 0)
1140-
appendStringInfoChar(&clientdetail, '\n');
1141-
appendStringInfo(&clientdetail, _("%s depends on %s"),
1154+
if (logdetail.len != 0)
1155+
appendStringInfoChar(&logdetail, '\n');
1156+
appendStringInfo(&logdetail, _("%s depends on %s"),
11421157
objDesc, otherDesc);
1143-
numReportedClient++;
1158+
pfree(otherDesc);
11441159
}
11451160
else
11461161
numNotReportedClient++;
1147-
/* separate entries with a newline */
1148-
if (logdetail.len != 0)
1149-
appendStringInfoChar(&logdetail, '\n');
1150-
appendStringInfo(&logdetail, _("%s depends on %s"),
1151-
objDesc, otherDesc);
1152-
pfree(otherDesc);
11531162
ok = false;
11541163
}
11551164
else

src/backend/catalog/pg_shdepend.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,12 @@ storeObjectDescription(StringInfo descs,
11971197
{
11981198
char *objdesc = getObjectDescription(object);
11991199

1200+
/*
1201+
* An object being dropped concurrently doesn't need to be reported.
1202+
*/
1203+
if (objdesc == NULL)
1204+
return;
1205+
12001206
/* separate entries with a newline */
12011207
if (descs->len != 0)
12021208
appendStringInfoChar(descs, '\n');

0 commit comments

Comments
 (0)