summaryrefslogtreecommitdiff
path: root/src/bin/scripts/vacuumdb.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:51 -0400
commitaed0387958e5774b60618b3cca52c6dad871cdba (patch)
tree843b6ec7fcb5deeaf9c328317efaf02b3428a88a /src/bin/scripts/vacuumdb.c
parentafabfcc0eb16d64bedeaf8152ef748f99edba55d (diff)
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/vacuumdb.c')
-rw-r--r--src/bin/scripts/vacuumdb.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 86e6ab359fa..eca703de228 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -236,16 +236,16 @@ main(int argc, char *argv[])
static void
-run_vacuum_command(PGconn *conn, const char *sql, bool echo, const char *dbname, const char *table, const char *progname)
+run_vacuum_command(PGconn *conn, const char *sql, bool echo, const char *table, const char *progname)
{
if (!executeMaintenanceCommand(conn, sql, echo))
{
if (table)
fprintf(stderr, _("%s: vacuuming of table \"%s\" in database \"%s\" failed: %s"),
- progname, table, dbname, PQerrorMessage(conn));
+ progname, table, PQdb(conn), PQerrorMessage(conn));
else
fprintf(stderr, _("%s: vacuuming of database \"%s\" failed: %s"),
- progname, dbname, PQerrorMessage(conn));
+ progname, PQdb(conn), PQerrorMessage(conn));
PQfinish(conn);
exit(1);
}
@@ -348,7 +348,7 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
fflush(stdout);
}
executeCommand(conn, stage_commands[i], progname, echo);
- run_vacuum_command(conn, sql.data, echo, dbname, table, progname);
+ run_vacuum_command(conn, sql.data, echo, table, progname);
}
}
else
@@ -361,12 +361,12 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
fflush(stdout);
}
executeCommand(conn, stage_commands[stage], progname, echo);
- run_vacuum_command(conn, sql.data, echo, dbname, table, progname);
+ run_vacuum_command(conn, sql.data, echo, table, progname);
}
}
else
- run_vacuum_command(conn, sql.data, echo, dbname, NULL, progname);
+ run_vacuum_command(conn, sql.data, echo, NULL, progname);
PQfinish(conn);
termPQExpBuffer(&sql);