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:
parent
fe8b95b7ea
commit
de8ffd6663
@ -406,6 +406,29 @@ ExecuteSqlQuery(Archive *AHX, const char *query, ExecStatusType status)
|
|||||||
return res;
|
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.
|
* Convenience function to send a query.
|
||||||
* Monitors result to detect COPY statements
|
* Monitors result to detect COPY statements
|
||||||
|
@ -15,6 +15,7 @@ extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, const char *buf, size_t bufLe
|
|||||||
extern void ExecuteSqlStatement(Archive *AHX, const char *query);
|
extern void ExecuteSqlStatement(Archive *AHX, const char *query);
|
||||||
extern PGresult *ExecuteSqlQuery(Archive *AHX, const char *query,
|
extern PGresult *ExecuteSqlQuery(Archive *AHX, const char *query,
|
||||||
ExecStatusType status);
|
ExecStatusType status);
|
||||||
|
extern PGresult *ExecuteSqlQueryForSingleRow(Archive *fout, char *query);
|
||||||
|
|
||||||
extern void EndDBCopyMode(ArchiveHandle *AH, struct _tocEntry * te);
|
extern void EndDBCopyMode(ArchiveHandle *AH, struct _tocEntry * te);
|
||||||
|
|
||||||
|
@ -283,7 +283,6 @@ static bool nonemptyReloptions(const char *reloptions);
|
|||||||
static void fmtReloptionsArray(Archive *fout, PQExpBuffer buffer,
|
static void fmtReloptionsArray(Archive *fout, PQExpBuffer buffer,
|
||||||
const char *reloptions, const char *prefix);
|
const char *reloptions, const char *prefix);
|
||||||
static char *get_synchronized_snapshot(Archive *fout);
|
static char *get_synchronized_snapshot(Archive *fout);
|
||||||
static PGresult *ExecuteSqlQueryForSingleRow(Archive *fout, char *query);
|
|
||||||
static void setupDumpWorker(Archive *AHX, RestoreOptions *ropt);
|
static void setupDumpWorker(Archive *AHX, RestoreOptions *ropt);
|
||||||
|
|
||||||
|
|
||||||
@ -15295,26 +15294,3 @@ fmtReloptionsArray(Archive *fout, PQExpBuffer buffer, const char *reloptions,
|
|||||||
if (options)
|
if (options)
|
||||||
free(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;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user