Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5bf1232

Browse files
committed
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
1 parent 9f12da7 commit 5bf1232

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/fe_utils/string_utils.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -790,29 +790,38 @@ appendPsqlMetaConnect(PQExpBuffer buf, const char *dbname)
790790
}
791791
}
792792

793-
appendPQExpBufferStr(buf, "\\connect ");
794793
if (complex)
795794
{
796795
PQExpBufferData connstr;
797796

798797
initPQExpBuffer(&connstr);
798+
799+
/*
800+
* Force the target psql's encoding to SQL_ASCII. We don't really
801+
* know the encoding of the database name, and it doesn't matter as
802+
* long as psql will forward it to the server unchanged.
803+
*/
804+
appendPQExpBufferStr(buf, "\\encoding SQL_ASCII\n");
805+
appendPQExpBufferStr(buf, "\\connect -reuse-previous=on ");
806+
799807
appendPQExpBufferStr(&connstr, "dbname=");
800808
appendConnStrVal(&connstr, dbname);
801809

802-
appendPQExpBufferStr(buf, "-reuse-previous=on ");
803-
804810
/*
805811
* As long as the name does not contain a newline, SQL identifier
806812
* quoting satisfies the psql meta-command parser. Prefer not to
807813
* involve psql-interpreted single quotes, which behaved differently
808814
* before PostgreSQL 9.2.
809815
*/
810-
appendPQExpBufferStr(buf, fmtId(connstr.data));
816+
appendPQExpBufferStr(buf, fmtIdEnc(connstr.data, PG_SQL_ASCII));
811817

812818
termPQExpBuffer(&connstr);
813819
}
814820
else
815-
appendPQExpBufferStr(buf, fmtId(dbname));
821+
{
822+
appendPQExpBufferStr(buf, "\\connect ");
823+
appendPQExpBufferStr(buf, fmtIdEnc(dbname, PG_SQL_ASCII));
824+
}
816825
appendPQExpBufferChar(buf, '\n');
817826
}
818827

0 commit comments

Comments
 (0)