]> granicus.if.org Git - postgresql/commitdiff
Check number of fields in IDENTIFY_SYSTEM response
authorMagnus Hagander <magnus@hagander.net>
Fri, 20 Jan 2012 12:57:02 +0000 (13:57 +0100)
committerMagnus Hagander <magnus@hagander.net>
Fri, 20 Jan 2012 12:57:02 +0000 (13:57 +0100)
Jaime Casanova

src/bin/pg_basebackup/pg_basebackup.c
src/bin/pg_basebackup/pg_receivexlog.c
src/bin/pg_basebackup/receivelog.c

index 40076802e5f9e28a85cf0a7bfdc5b713990efbaf..aabbdac8d007f05f9df56881822c011f532e0916 100644 (file)
@@ -918,10 +918,10 @@ BaseBackup(void)
                                progname, PQerrorMessage(conn));
                disconnect_and_exit(1);
        }
-       if (PQntuples(res) != 1)
+       if (PQntuples(res) != 1 || PQnfields(res) != 3)
        {
-               fprintf(stderr, _("%s: could not identify system, got %i rows\n"),
-                               progname, PQntuples(res));
+               fprintf(stderr, _("%s: could not identify system, got %i rows and %i fields\n"),
+                               progname, PQntuples(res), PQnfields(res));
                disconnect_and_exit(1);
        }
        sysidentifier = strdup(PQgetvalue(res, 0, 0));
@@ -1130,7 +1130,7 @@ BaseBackup(void)
                {
                        fprintf(stderr, _("%s: could not parse xlog end position \"%s\"\n"),
                                        progname, xlogend);
-                       exit(1);
+                       disconnect_and_exit(1);
                }
                InterlockedIncrement(&has_xlogendptr);
 
@@ -1162,6 +1162,7 @@ BaseBackup(void)
        /*
         * End of copy data. Final result is already checked inside the loop.
         */
+       PQclear(res);
        PQfinish(conn);
 
        if (verbose)
index e698b06b7d3417ad5546aec19b9be8238c37c776..fe9e39bb2143fbb4e1c7448ac5925b9eddb7b3ef 100644 (file)
@@ -235,10 +235,10 @@ StreamLog(void)
                                progname, PQerrorMessage(conn));
                disconnect_and_exit(1);
        }
-       if (PQntuples(res) != 1)
+       if (PQntuples(res) != 1 || PQnfields(res) != 3)
        {
-               fprintf(stderr, _("%s: could not identify system, got %i rows\n"),
-                               progname, PQntuples(res));
+               fprintf(stderr, _("%s: could not identify system, got %i rows and %i fields\n"),
+                               progname, PQntuples(res), PQnfields(res));
                disconnect_and_exit(1);
        }
        timeline = atoi(PQgetvalue(res, 0, 1));
index c390cbf13dfd4c536079733da20646202b341aca..8ca3882a72927d3ffc3c600b0d30e5e27c592fb9 100644 (file)
@@ -235,6 +235,13 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
                        PQclear(res);
                        return false;
                }
+               if (PQnfields(res) != 3 || PQntuples(res) != 1)
+               {
+                       fprintf(stderr, _("%s: could not identify system, got %i rows and %i fields\n"),
+                                       progname, PQntuples(res), PQnfields(res));
+                       PQclear(res);
+                       return false;
+               }
                if (strcmp(sysidentifier, PQgetvalue(res, 0, 0)) != 0)
                {
                        fprintf(stderr, _("%s: system identifier does not match between base backup and streaming connection\n"), progname);