1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-02 11:44:50 +03:00

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
This commit is contained in:
Noah Misch 2018-02-26 07:39:48 -08:00
parent fe8b95b7ea
commit de8ffd6663
3 changed files with 24 additions and 24 deletions

View File

@ -406,6 +406,29 @@ ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
return res;
}
/*
* 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

View File

@ -15,6 +15,7 @@ extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLe
extern void ExecuteSqlStatement(Archive *AHX, const char *query);
extern PGresult *ExecuteSqlQuery(Archive *AHX, const char *query,
ExecStatusType status);
extern PGresult *ExecuteSqlQueryForSingleRow(Archive *fout, char *query);
extern void EndDBCopyMode(ArchiveHandle *AH, struct _tocEntry * te);

View File

@ -283,7 +283,6 @@ static bool nonemptyReloptions(const char *reloptions);
static void fmtReloptionsArray(Archive *fout, PQExpBuffer buffer,
const char *reloptions, const char *prefix);
static char *get_synchronized_snapshot(Archive *fout);
static PGresult *ExecuteSqlQueryForSingleRow(Archive *fout, char *query);
static void setupDumpWorker(Archive *AHX, RestoreOptions *ropt);
@ -15295,26 +15294,3 @@ fmtReloptionsArray(Archive *fout, PQExpBuffer buffer, const char *reloptions,
if (options)
free(options);
}
/*
* Execute an SQL query and verify that we got exactly one row back.
*/
static 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;
}