public inbox for [email protected]  
help / color / mirror / Atom feed
From: SATYANARAYANA NARLAPURAM <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: Add null check on get_tablespace_name() return in pg_get_database_ddl_internal
Date: Wed, 22 Apr 2026 15:20:36 -0700
Message-ID: <CAHg+QDd4mVPTT1P1E8o1k+2UzHkp55595v2GWpm9dENRwJCuYQ@mail.gmail.com> (raw)

Hi Hackers,

A concurrent tablespace drop could lead to null deref in
pg_get_database_ddl. I acknowledge this is a corner case. Adding a patch to
fix this to keep the code clean.

Thanks,
Satya


Attachments:

  [application/octet-stream] 0001-Fix-NULL-deref-in-pg_get_database_ddl-on-concurrent-tablespace-drop.patch (558B, 3-0001-Fix-NULL-deref-in-pg_get_database_ddl-on-concurrent-tablespace-drop.patch)
  download | inline diff:
diff --git a/src/backend/utils/adt/ddlutils.c b/src/backend/utils/adt/ddlutils.c
index d83cda33..cc7511e8 100644
--- a/src/backend/utils/adt/ddlutils.c
+++ b/src/backend/utils/adt/ddlutils.c
@@ -986,7 +986,8 @@ pg_get_database_ddl_internal(Oid dbid, bool pretty,
 	{
 		char	   *spcname = get_tablespace_name(dbform->dattablespace);
 
-		if (pg_strcasecmp(spcname, "pg_default") != 0)
+		if (spcname != NULL &&
+			pg_strcasecmp(spcname, "pg_default") != 0)
 			append_ddl_option(&buf, pretty, 4, "TABLESPACE = %s",
 							  quote_identifier(spcname));
 	}


view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Add null check on get_tablespace_name() return in pg_get_database_ddl_internal
  In-Reply-To: <CAHg+QDd4mVPTT1P1E8o1k+2UzHkp55595v2GWpm9dENRwJCuYQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox