aboutsummaryrefslogtreecommitdiff
path: root/src/bin/scripts/reindexdb.c
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2016-08-08 10:07:46 -0400
committerNoah Misch <noah@leadboat.com>2016-08-08 10:07:46 -0400
commitc400717172d77e5b07e51e04c5e5e13da181572e (patch)
treefb34ab115b929b8a0dc19ca375a2fe9441481d57 /src/bin/scripts/reindexdb.c
parent9d924e9a64b91571e04252424c01210fc0f6f6d9 (diff)
downloadpostgresql-c400717172d77e5b07e51e04c5e5e13da181572e.tar.gz
postgresql-c400717172d77e5b07e51e04c5e5e13da181572e.zip
Field conninfo strings throughout src/bin/scripts.
These programs nominally accepted conninfo strings, but they would proceed to use the original dbname parameter as though it were an unadorned database name. This caused "reindexdb dbname=foo" to issue an SQL command that always failed, and other programs printed a conninfo string in error messages that purported to print a database name. Fix both problems by using PQdb() to retrieve actual database names. Continue to print the full conninfo string when reporting a connection failure. It is informative there, and if the database name is the sole problem, the server-side error message will include the name. Beyond those user-visible fixes, this allows a subsequent commit to synthesize and use conninfo strings without that implementation detail leaking into messages. As a side effect, the "vacuuming database" message now appears after, not before, the connection attempt. Back-patch to 9.1 (all supported versions). Reviewed by Michael Paquier and Peter Eisentraut. Security: CVE-2016-5424
Diffstat (limited to 'src/bin/scripts/reindexdb.c')
-rw-r--r--src/bin/scripts/reindexdb.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c
index 0c8c90c22a4..43f61013ef1 100644
--- a/src/bin/scripts/reindexdb.c
+++ b/src/bin/scripts/reindexdb.c
@@ -264,7 +264,7 @@ main(int argc, char *argv[])
* specified
*/
if (indexes.head == NULL && tables.head == NULL && schemas.head == NULL)
- reindex_one_database(dbname, dbname, "DATABASE", host, port,
+ reindex_one_database(NULL, dbname, "DATABASE", host, port,
username, prompt_password, progname, echo, verbose);
}
@@ -281,6 +281,9 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
PGconn *conn;
+ conn = connectDatabase(dbname, host, port, username, prompt_password,
+ progname, false, false);
+
initPQExpBuffer(&sql);
appendPQExpBufferStr(&sql, "REINDEX");
@@ -295,26 +298,23 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
else if (strcmp(type, "SCHEMA") == 0)
appendPQExpBuffer(&sql, " SCHEMA %s", name);
else if (strcmp(type, "DATABASE") == 0)
- appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
+ appendPQExpBuffer(&sql, " DATABASE %s", fmtId(PQdb(conn)));
appendPQExpBufferChar(&sql, ';');
- conn = connectDatabase(dbname, host, port, username, prompt_password,
- progname, false, false);
-
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
if (strcmp(type, "TABLE") == 0)
fprintf(stderr, _("%s: reindexing of table \"%s\" in database \"%s\" failed: %s"),
- progname, name, dbname, PQerrorMessage(conn));
+ progname, name, PQdb(conn), PQerrorMessage(conn));
if (strcmp(type, "INDEX") == 0)
fprintf(stderr, _("%s: reindexing of index \"%s\" in database \"%s\" failed: %s"),
- progname, name, dbname, PQerrorMessage(conn));
+ progname, name, PQdb(conn), PQerrorMessage(conn));
if (strcmp(type, "SCHEMA") == 0)
fprintf(stderr, _("%s: reindexing of schema \"%s\" in database \"%s\" failed: %s"),
- progname, name, dbname, PQerrorMessage(conn));
+ progname, name, PQdb(conn), PQerrorMessage(conn));
else
fprintf(stderr, _("%s: reindexing of database \"%s\" failed: %s"),
- progname, dbname, PQerrorMessage(conn));
+ progname, PQdb(conn), PQerrorMessage(conn));
PQfinish(conn);
exit(1);
}
@@ -360,9 +360,11 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
const char *username, enum trivalue prompt_password,
const char *progname, bool echo, bool verbose)
{
+ PGconn *conn;
PQExpBufferData sql;
- PGconn *conn;
+ conn = connectDatabase(dbname, host, port, username, prompt_password,
+ progname, false, false);
initPQExpBuffer(&sql);
@@ -371,10 +373,8 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
if (verbose)
appendPQExpBuffer(&sql, " (VERBOSE)");
- appendPQExpBuffer(&sql, " SYSTEM %s;", dbname);
+ appendPQExpBuffer(&sql, " SYSTEM %s;", PQdb(conn));
- conn = connectDatabase(dbname, host, port, username, prompt_password,
- progname, false, false);
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
fprintf(stderr, _("%s: reindexing of system catalogs failed: %s"),