Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d74b54b

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 df80f9d commit d74b54b

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/backend/catalog/dependency.c

+20-11
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,10 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
10941094

10951095
objDesc = getObjectDescription(obj, false);
10961096

1097+
/* An object being dropped concurrently doesn't need to be reported */
1098+
if (objDesc == NULL)
1099+
continue;
1100+
10971101
/*
10981102
* If, at any stage of the recursive search, we reached the object via
10991103
* an AUTO, INTERNAL, PARTITION, or EXTENSION dependency, then it's
@@ -1119,23 +1123,28 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
11191123
char *otherDesc = getObjectDescription(&extra->dependee,
11201124
false);
11211125

1122-
if (numReportedClient < MAX_REPORTED_DEPS)
1126+
if (otherDesc)
11231127
{
1128+
if (numReportedClient < MAX_REPORTED_DEPS)
1129+
{
1130+
/* separate entries with a newline */
1131+
if (clientdetail.len != 0)
1132+
appendStringInfoChar(&clientdetail, '\n');
1133+
appendStringInfo(&clientdetail, _("%s depends on %s"),
1134+
objDesc, otherDesc);
1135+
numReportedClient++;
1136+
}
1137+
else
1138+
numNotReportedClient++;
11241139
/* separate entries with a newline */
1125-
if (clientdetail.len != 0)
1126-
appendStringInfoChar(&clientdetail, '\n');
1127-
appendStringInfo(&clientdetail, _("%s depends on %s"),
1140+
if (logdetail.len != 0)
1141+
appendStringInfoChar(&logdetail, '\n');
1142+
appendStringInfo(&logdetail, _("%s depends on %s"),
11281143
objDesc, otherDesc);
1129-
numReportedClient++;
1144+
pfree(otherDesc);
11301145
}
11311146
else
11321147
numNotReportedClient++;
1133-
/* separate entries with a newline */
1134-
if (logdetail.len != 0)
1135-
appendStringInfoChar(&logdetail, '\n');
1136-
appendStringInfo(&logdetail, _("%s depends on %s"),
1137-
objDesc, otherDesc);
1138-
pfree(otherDesc);
11391148
ok = false;
11401149
}
11411150
else

src/backend/catalog/pg_shdepend.c

+6
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,12 @@ storeObjectDescription(StringInfo descs,
12341234
{
12351235
char *objdesc = getObjectDescription(object, false);
12361236

1237+
/*
1238+
* An object being dropped concurrently doesn't need to be reported.
1239+
*/
1240+
if (objdesc == NULL)
1241+
return;
1242+
12371243
/* separate entries with a newline */
12381244
if (descs->len != 0)
12391245
appendStringInfoChar(descs, '\n');

0 commit comments

Comments
 (0)