Skip to content

Commit 3eff168

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 7dc9a31 commit 3eff168

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

11091109
objDesc = getObjectDescription(obj);
11101110

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

1135-
if (numReportedClient < MAX_REPORTED_DEPS)
1139+
if (otherDesc)
11361140
{
1141+
if (numReportedClient < MAX_REPORTED_DEPS)
1142+
{
1143+
/* separate entries with a newline */
1144+
if (clientdetail.len != 0)
1145+
appendStringInfoChar(&clientdetail, '\n');
1146+
appendStringInfo(&clientdetail, _("%s depends on %s"),
1147+
objDesc, otherDesc);
1148+
numReportedClient++;
1149+
}
1150+
else
1151+
numNotReportedClient++;
11371152
/* separate entries with a newline */
1138-
if (clientdetail.len != 0)
1139-
appendStringInfoChar(&clientdetail, '\n');
1140-
appendStringInfo(&clientdetail, _("%s depends on %s"),
1153+
if (logdetail.len != 0)
1154+
appendStringInfoChar(&logdetail, '\n');
1155+
appendStringInfo(&logdetail, _("%s depends on %s"),
11411156
objDesc, otherDesc);
1142-
numReportedClient++;
1157+
pfree(otherDesc);
11431158
}
11441159
else
11451160
numNotReportedClient++;
1146-
/* separate entries with a newline */
1147-
if (logdetail.len != 0)
1148-
appendStringInfoChar(&logdetail, '\n');
1149-
appendStringInfo(&logdetail, _("%s depends on %s"),
1150-
objDesc, otherDesc);
1151-
pfree(otherDesc);
11521161
ok = false;
11531162
}
11541163
else

src/backend/catalog/pg_shdepend.c

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

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

0 commit comments

Comments
 (0)