diff options
author | Alvaro Herrera | 2021-11-05 15:29:34 +0000 |
---|---|---|
committer | Alvaro Herrera | 2021-11-05 15:29:34 +0000 |
commit | 92224e470c830e73636de20689690f28037cd019 (patch) | |
tree | ef7dc09afbfaa5d999c096df7d8eab48bcdd2416 | |
parent | b110af5f7c9fbfdef3451cd8878342757deef89d (diff) |
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.c | 31 | ||||
-rw-r--r-- | src/backend/catalog/pg_shdepend.c | 6 |
2 files changed, 26 insertions, 11 deletions
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c index 47ad2e83da9..d138b6a0d27 100644 --- a/src/backend/catalog/dependency.c +++ b/src/backend/catalog/dependency.c @@ -910,6 +910,10 @@ reportDependentObjects(const ObjectAddresses *targetObjects, objDesc = getObjectDescription(obj); + /* 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, or EXTENSION dependency, then it's okay to @@ -933,23 +937,28 @@ reportDependentObjects(const ObjectAddresses *targetObjects, { char *otherDesc = getObjectDescription(&extra->dependee); - 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 a24e2cefa06..ff7a1eb8247 100644 --- a/src/backend/catalog/pg_shdepend.c +++ b/src/backend/catalog/pg_shdepend.c @@ -1113,6 +1113,12 @@ storeObjectDescription(StringInfo descs, { char *objdesc = getObjectDescription(object); + /* + * 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'); |