8000 Field conninfo strings throughout src/bin/scripts. · edgarlanting/postgres@ba8c408 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba8c408

Browse files
committed
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
1 parent cf7e5f5 commit ba8c408

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/bin/scripts/clusterdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ cluster_one_database(const char *dbname, bool verbose, const char *table,
185185
{
186186
if (table)
187187
fprintf(stderr, _("%s: clustering of table \"%s\" in database \"%s\" failed: %s"),
188-
progname, table, dbname, PQerrorMessage(conn));
188+
progname, table, PQdb(conn), PQerrorMessage(conn));
189189
else
190190
fprintf(stderr, _("%s: clustering of database \"%s\" failed: %s"),
191-
progname, dbname, PQerrorMessage(conn));
191+
progname, PQdb(conn), PQerrorMessage(conn));
192192
PQfinish(conn);
193193
exit(1);
194194
}

src/bin/scripts/createlang.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ main(int argc, char *argv[])
179179
result = executeQuery(conn, sql.data, progname, echo);
180180
if (PQntuples(result) > 0)
181181
{
182-
PQfinish(conn);
183182
fprintf(stderr,
184183
_("%s: language \"%s\" is already installed in database \"%s\"\n"),
185-
progname, langname, dbname);
184+
progname, langname, PQdb(conn));
185+
PQfinish(conn);
186186
/* separate exit status for "already installed" */
187187
exit(2);
188188
}

src/bin/scripts/droplang.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ main(int argc, char *argv[])
186186
result = executeQuery(conn, sql.data, progname, echo);
187187
if (PQntuples(result) == 0)
188188
{
189-
PQfinish(conn);
190189
fprintf(stderr, _("%s: language \"%s\" is not installed in "
191190
"database \"%s\"\n"),
192-
progname, langname, dbname);
191+
progname, langname, PQdb(conn));
192+
PQfinish(conn);
193193
exit(1);
194194
}
195195
PQclear(result);

src/bin/scripts/reindexdb.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ main(int argc, char *argv[])
203203
username, prompt_password, progname, echo);
204204
/* reindex database only if index or table is not specified */
205205
if (index == NULL && table == NULL)
206-
reindex_one_database(dbname, dbname, "DATABASE", host, port,
206+
reindex_one_database(NULL, dbname, "DATABASE", host, port,
207207
username, prompt_password, progname, echo);
208208
}
209209

@@ -219,6 +219,8 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
219219

220220
PGconn *conn;
221221

222+
conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
223+
222224
initPQExpBuffer(&sql);
223225

224226
appendPQExpBuffer(&sql, "REINDEX");
@@ -227,22 +229,20 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
227229
else if (strcmp(type, "INDEX") == 0)
228230
appendPQExpBuffer(&sql, " INDEX %s", fmtId(name));
229231
else if (strcmp(type, "DATABASE") == 0)
230-
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
232+
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(PQdb(conn)));
231233
appendPQExpBuffer(&sql, ";\n");
232234

233-
conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
234-
235235
if (!executeMaintenanceCommand(conn, sql.data, echo))
236236
{
237237
if (strcmp(type, "TABLE") == 0)
238238
fprintf(stderr, _("%s: reindexing of table \"%s\" in database \"%s\" failed: %s"),
239-
progname, name, dbname, PQerrorMessage(conn));
239+
progname, name, PQdb(conn), PQerrorMessage(conn));
240240
if (strcmp(type, "INDEX") == 0)
241241
fprintf(stderr, _("%s: reindexing of index \"%s\" in database \"%s\" failed: %s"),
242-
progname, name, dbname, PQerrorMessage(conn));
242+
progname, name, PQdb(conn), PQerrorMessage(conn));
243243
else
244244
fprintf(stderr, _("%s: reindexing of database \"%s\" failed: %s"),
245-
progname, dbname, PQerrorMessage(conn));
245+
progname, PQdb(conn), PQerrorMessage(conn));
246246
PQfinish(conn);
247247
exit(1);
248248
}
@@ -286,15 +286,15 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
286286
const char *username, enum trivalue prompt_password,
287287
const char *progname, bool echo)
288288
{
289+
PGconn *conn;
289290
PQExpBufferData sql;
290291

291-
PGconn *conn;
292+
conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
292293

293294
initPQExpBuffer(&sql);
294295

295-
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;\n", dbname);
296+
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;\n", PQdb(conn));
296297

297-
conn = connectDatabase(dbname, host, port, username, prompt_password, progname);
298298
if (!executeMaintenanceCommand(conn, sql.data, echo))
299299
{
300300
fprintf(stderr, _("%s: reindexing of system catalogs failed: %s"),

src/bin/scripts/vacuumdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,10 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
276276
{
277277
if (table)
278278
fprintf(stderr, _("%s: vacuuming of table \"%s\" in database \"%s\" failed: %s"),
279-
progname, table, dbname, PQerrorMessage(conn));
279+
progname, table, PQdb(conn), PQerrorMessage(conn));
280280
else
281281
fprintf(stderr, _("%s: vacuuming of database \"%s\" failed: %s"),
282-
progname, dbname, PQerrorMessage(conn));
282+
progname, PQdb(conn), PQerrorMessage(conn));
283283
PQfinish(conn);
284284
exit(1);
285285
}

0 commit comments

Comments
 (0)
0