mirror of
https://github.com/postgres/postgres.git
synced 2025-06-30 21:42:05 +03:00
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
This commit is contained in:
@ -129,13 +129,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";
|
||||
@ -149,6 +142,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);
|
||||
|
Reference in New Issue
Block a user