mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Adapt appendPsqlMetaConnect() to the new fmtId() encoding expectations.
We need to tell fmtId() what encoding to assume, but this function doesn't know that. Fortunately we can fix that without changing the function's API, because we can just use SQL_ASCII. That's because database names in connection requests are effectively binary not text: no encoding-aware processing will happen on them. This fixes XversionUpgrade failures seen in the buildfarm. The alternative of having pg_upgrade use setFmtEncoding() is unappetizing, given that it's connecting to multiple databases that may have different encodings. Andres Freund, Noah Misch, Tom Lane Security: CVE-2025-1094
This commit is contained in:
parent
7beb2af5e6
commit
f9fceef6ee
@ -790,29 +790,38 @@ appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appendPQExpBufferStr(buf, "\\connect ");
|
|
||||||
if (complex)
|
if (complex)
|
||||||
{
|
{
|
||||||
PQExpBufferData connstr;
|
PQExpBufferData connstr;
|
||||||
|
|
||||||
initPQExpBuffer(&connstr);
|
initPQExpBuffer(&connstr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Force the target psql's encoding to SQL_ASCII. We don't really
|
||||||
|
* know the encoding of the database name, and it doesn't matter as
|
||||||
|
* long as psql will forward it to the server unchanged.
|
||||||
|
*/
|
||||||
|
appendPQExpBufferStr(buf, "\\encoding SQL_ASCII\n");
|
||||||
|
appendPQExpBufferStr(buf, "\\connect -reuse-previous=on ");
|
||||||
|
|
||||||
appendPQExpBufferStr(&connstr, "dbname=");
|
appendPQExpBufferStr(&connstr, "dbname=");
|
||||||
appendConnStrVal(&connstr, dbname);
|
appendConnStrVal(&connstr, dbname);
|
||||||
|
|
||||||
appendPQExpBufferStr(buf, "-reuse-previous=on ");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* As long as the name does not contain a newline, SQL identifier
|
* As long as the name does not contain a newline, SQL identifier
|
||||||
* quoting satisfies the psql meta-command parser. Prefer not to
|
* quoting satisfies the psql meta-command parser. Prefer not to
|
||||||
* involve psql-interpreted single quotes, which behaved differently
|
* involve psql-interpreted single quotes, which behaved differently
|
||||||
* before PostgreSQL 9.2.
|
* before PostgreSQL 9.2.
|
||||||
*/
|
*/
|
||||||
appendPQExpBufferStr(buf, fmtId(connstr.data));
|
appendPQExpBufferStr(buf, fmtIdEnc(connstr.data, PG_SQL_ASCII));
|
||||||
|
|
||||||
termPQExpBuffer(&connstr);
|
termPQExpBuffer(&connstr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
appendPQExpBufferStr(buf, fmtId(dbname));
|
{
|
||||||
|
appendPQExpBufferStr(buf, "\\connect ");
|
||||||
|
appendPQExpBufferStr(buf, fmtIdEnc(dbname, PG_SQL_ASCII));
|
||||||
|
}
|
||||||
appendPQExpBufferChar(buf, '\n');
|
appendPQExpBufferChar(buf, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user