1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-03 15:22:11 +03:00

Obstruct shell, SQL, and conninfo injection via database and role names.

Due to simplistic quoting and confusion of database names with conninfo
strings, roles with the CREATEDB or CREATEROLE option could escalate to
superuser privileges when a superuser next ran certain maintenance
commands.  The new coding rule for PQconnectdbParams() calls, documented
at conninfo_array_parse(), is to pass expand_dbname=true and wrap
literal database names in a trivial connection string.  Escape
zero-length values in appendConnStrVal().  Back-patch to 9.1 (all
supported versions).

Nathan Bossart, Michael Paquier, and Noah Misch.  Reviewed by Peter
Eisentraut.  Reported by Nathan Bossart.

Security: CVE-2016-5424
This commit is contained in:
Noah Misch
2016-08-08 10:07:46 -04:00
parent 8adff37830
commit 286c8bc646
21 changed files with 656 additions and 207 deletions

View File

@@ -539,6 +539,7 @@ vacuum_all_databases(vacuumingOptions *vacopts,
{
PGconn *conn;
PGresult *result;
PQExpBufferData connstr;
int stage;
int i;
@@ -549,6 +550,7 @@ vacuum_all_databases(vacuumingOptions *vacopts,
progname, echo);
PQfinish(conn);
initPQExpBuffer(&connstr);
if (analyze_in_stages)
{
/*
@@ -563,10 +565,11 @@ vacuum_all_databases(vacuumingOptions *vacopts,
{
for (i = 0; i < PQntuples(result); i++)
{
const char *dbname;
resetPQExpBuffer(&connstr);
appendPQExpBuffer(&connstr, "dbname=");
appendConnStrVal(&connstr, PQgetvalue(result, i, 0));
dbname = PQgetvalue(result, i, 0);
vacuum_one_database(dbname, vacopts,
vacuum_one_database(connstr.data, vacopts,
stage,
NULL,
host, port, username, prompt_password,
@@ -579,10 +582,11 @@ vacuum_all_databases(vacuumingOptions *vacopts,
{
for (i = 0; i < PQntuples(result); i++)
{
const char *dbname;
resetPQExpBuffer(&connstr);
appendPQExpBuffer(&connstr, "dbname=");
appendConnStrVal(&connstr, PQgetvalue(result, i, 0));
dbname = PQgetvalue(result, i, 0);
vacuum_one_database(dbname, vacopts,
vacuum_one_database(connstr.data, vacopts,
ANALYZE_NO_STAGE,
NULL,
host, port, username, prompt_password,
@@ -590,6 +594,7 @@ vacuum_all_databases(vacuumingOptions *vacopts,
progname, echo, quiet);
}
}
termPQExpBuffer(&connstr);
PQclear(result);
}