diff options
author | Noah Misch <noah@leadboat.com> | 2018-02-26 07:39:48 -0800 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2018-02-26 07:39:48 -0800 |
commit | de8ffd6663fbe5a263ff1abc2820f7d6a00ba9a9 (patch) | |
tree | bf8af0768eff384b733ef95a36f5faa0e458a469 /src/bin/pg_dump/pg_backup_db.c | |
parent | fe8b95b7ea0c6e4294c4c97c555bc7f3492c0e33 (diff) |
Back-patch non-static ExecuteSqlQueryForSingleRow().
Back-patch a subset of commit 47e59697679a0877e0525c565b1be437487604a7
to 9.4 and 9.3. The next commit adds calls to this function.
Security: CVE-2018-1058
Diffstat (limited to 'src/bin/pg_dump/pg_backup_db.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_db.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index 60e9deaba73..fea10bce298 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -407,6 +407,29 @@ ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status) } /* + * Execute an SQL query and verify that we got exactly one row back. + */ +PGresult * +ExecuteSqlQueryForSingleRow(Archive *fout, char *query) +{ + PGresult *res; + int ntups; + + res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK); + + /* Expecting a single result only */ + ntups = PQntuples(res); + if (ntups != 1) + exit_horribly(NULL, + ngettext("query returned %d row instead of one: %s\n", + "query returned %d rows instead of one: %s\n", + ntups), + ntups, query); + + return res; +} + +/* * Convenience function to send a query. * Monitors result to detect COPY statements */ |