Back-patch non-static ExecuteSqlQueryForSingleRow().
authorNoah Misch <noah@leadboat.com>
Mon, 26 Feb 2018 15:39:48 +0000 (07:39 -0800)
committerNoah Misch <noah@leadboat.com>
Mon, 26 Feb 2018 15:39:48 +0000 (07:39 -0800)
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

src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_backup_db.h
src/bin/pg_dump/pg_dump.c

index e4b58d58aeedf9e10856aa9636ba1dd4b073730a..cbfdf4889e8d1248faba3bc62487f34c34b3b19b 100644 (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
index 2eea1c33ebd36d057b63dc242fbf706b20e57c20..b7036e6bd803d7796af269198d6a3eeaa61ba5a8 100644 (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);
 
index 7fd3ff300b8ae024c1f531dd80a78c02d9efeb24..10607644889669407a277a7e49efe0fdbdd98369 100644 (file)
@@ -281,7 +281,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);
 
 
@@ -15638,26 +15637,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;
-}