aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2021-11-05 12:29:35 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2021-11-05 12:29:35 -0300
commitd74b54b3ddf710926a44bf3f9c87c00e6f82d825 (patch)
tree0f76a43eb2be17ba29166c80b962556604966dce
parentdf80f9da5c6541e744eeb20eaca919c7fc189999 (diff)
downloadpostgresql-d74b54b3ddf710926a44bf3f9c87c00e6f82d825.tar.gz
postgresql-d74b54b3ddf710926a44bf3f9c87c00e6f82d825.zip
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
-rw-r--r--src/backend/catalog/dependency.c31
-rw-r--r--src/backend/catalog/pg_shdepend.c6
2 files changed, 26 insertions, 11 deletions
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index 9f8eb1a37fd..fe9c714257f 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1094,6 +1094,10 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
objDesc = getObjectDescription(obj, false);
+ /* An object being dropped concurrently doesn't need to be reported */
+ if (objDesc == NULL)
+ continue;
+
/*
* If, at any stage of the recursive search, we reached the object via
* an AUTO, INTERNAL, PARTITION, or EXTENSION dependency, then it's
@@ -1119,23 +1123,28 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
char *otherDesc = getObjectDescription(&extra->dependee,
false);
- if (numReportedClient < MAX_REPORTED_DEPS)
+ if (otherDesc)
{
+ if (numReportedClient < MAX_REPORTED_DEPS)
+ {
+ /* separate entries with a newline */
+ if (clientdetail.len != 0)
+ appendStringInfoChar(&clientdetail, '\n');
+ appendStringInfo(&clientdetail, _("%s depends on %s"),
+ objDesc, otherDesc);
+ numReportedClient++;
+ }
+ else
+ numNotReportedClient++;
/* separate entries with a newline */
- if (clientdetail.len != 0)
- appendStringInfoChar(&clientdetail, '\n');
- appendStringInfo(&clientdetail, _("%s depends on %s"),
+ if (logdetail.len != 0)
+ appendStringInfoChar(&logdetail, '\n');
+ appendStringInfo(&logdetail, _("%s depends on %s"),
objDesc, otherDesc);
- numReportedClient++;
+ pfree(otherDesc);
}
else
numNotReportedClient++;
- /* separate entries with a newline */
- if (logdetail.len != 0)
- appendStringInfoChar(&logdetail, '\n');
- appendStringInfo(&logdetail, _("%s depends on %s"),
- objDesc, otherDesc);
- pfree(otherDesc);
ok = false;
}
else
diff --git a/src/backend/catalog/pg_shdepend.c b/src/backend/catalog/pg_shdepend.c
index 8453d8fefd7..9ea42f805fa 100644
--- a/src/backend/catalog/pg_shdepend.c
+++ b/src/backend/catalog/pg_shdepend.c
@@ -1234,6 +1234,12 @@ storeObjectDescription(StringInfo descs,
{
char *objdesc = getObjectDescription(object, false);
+ /*
+ * An object being dropped concurrently doesn't need to be reported.
+ */
+ if (objdesc == NULL)
+ return;
+
/* separate entries with a newline */
if (descs->len != 0)
appendStringInfoChar(descs, '\n');