summaryrefslogtreecommitdiff
path: root/src/bin/scripts/dropdb.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2025-02-10 10:03:40 -0500
committerAndres Freund <andres@anarazel.de>2025-02-10 10:03:40 -0500
commit5df4e1632e65323ad9b33d7dfe721117a6060fbe (patch)
tree69dd095229a523158fc7341412beea65f16229c1 /src/bin/scripts/dropdb.c
parentdb3eb0e8256a7089d16cb6ed1ea7a65654c0e105 (diff)
Specify the encoding of input to fmtId()
This commit adds fmtIdEnc() and fmtQualifiedIdEnc(), which allow to specify the encoding as an explicit argument. Additionally setFmtEncoding() is provided, which defines the encoding when no explicit encoding is provided, to avoid breaking all code using fmtId(). All users of fmtId()/fmtQualifiedId() are either converted to the explicit version or a call to setFmtEncoding() has been added. This commit does not yet utilize the now well-defined encoding, that will happen in a subsequent commit. Reviewed-by: Noah Misch <noah@leadboat.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Backpatch-through: 13 Security: CVE-2025-1094
Diffstat (limited to 'src/bin/scripts/dropdb.c')
-rw-r--r--src/bin/scripts/dropdb.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c
index ccbf78e91a8..02ebaedd494 100644
--- a/src/bin/scripts/dropdb.c
+++ b/src/bin/scripts/dropdb.c
@@ -127,13 +127,6 @@ main(int argc, char *argv[])
exit(0);
}
- initPQExpBuffer(&sql);
-
- appendPQExpBuffer(&sql, "DROP DATABASE %s%s%s;",
- (if_exists ? "IF EXISTS " : ""),
- fmtId(dbname),
- force ? " WITH (FORCE)" : "");
-
/* Avoid trying to drop postgres db while we are connected to it. */
if (maintenance_db == NULL && strcmp(dbname, "postgres") == 0)
maintenance_db = "template1";
@@ -147,6 +140,12 @@ main(int argc, char *argv[])
conn = connectMaintenanceDatabase(&cparams, progname, echo);
+ initPQExpBuffer(&sql);
+ appendPQExpBuffer(&sql, "DROP DATABASE %s%s%s;",
+ (if_exists ? "IF EXISTS " : ""),
+ fmtIdEnc(dbname, PQclientEncoding(conn)),
+ force ? " WITH (FORCE)" : "");
+
if (echo)
printf("%s\n", sql.data);
result = PQexec(conn, sql.data);