Skip to content

Commit c145349

Browse files
committed
Check number of fields in IDENTIFY_SYSTEM response
Jaime Casanova
1 parent 356fddf commit c145349

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,10 @@ BaseBackup(void)
918918
progname, PQerrorMessage(conn));
919919
disconnect_and_exit(1);
920920
}
921-
if (PQntuples(res) != 1)
921+
if (PQntuples(res) != 1 || PQnfields(res) != 3)
922922
{
923-
fprintf(stderr, _("%s: could not identify system, got %i rows\n"),
924-
progname, PQntuples(res));
923+
fprintf(stderr, _("%s: could not identify system, got %i rows and %i fields\n"),
924+
progname, PQntuples(res), PQnfields(res));
925925
disconnect_and_exit(1);
926926
}
927927
sysidentifier = strdup(PQgetvalue(res, 0, 0));
@@ -1130,7 +1130,7 @@ BaseBackup(void)
11301130
{
11311131
fprintf(stderr, _("%s: could not parse xlog end position \"%s\"\n"),
11321132
progname, xlogend);
1133-
exit(1);
1133+
disconnect_and_exit(1);
11341134
}
11351135
InterlockedIncrement(&has_xlogendptr);
11361136

@@ -1162,6 +1162,7 @@ BaseBackup(void)
11621162
/*
11631163
* End of copy data. Final result is already checked inside the loop.
11641164
*/
1165+
PQclear(res);
11651166
PQfinish(conn);
11661167

11671168
if (verbose)

src/bin/pg_basebackup/pg_receivexlog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ StreamLog(void)
235235
progname, PQerrorMessage(conn));
236236
disconnect_and_exit(1);
237237
}
238-
if (PQntuples(res) != 1)
238+
if (PQntuples(res) != 1 || PQnfields(res) != 3)
239239
{
240-
fprintf(stderr, _("%s: could not identify system, got %i rows\n"),
241-
progname, PQntuples(res));
240+
fprintf(stderr, _("%s: could not identify system, got %i rows and %i fields\n"),
241+
progname, PQntuples(res), PQnfields(res));
242242
disconnect_and_exit(1);
243243
}
244244
timeline = atoi(PQgetvalue(res, 0, 1));

src/bin/pg_basebackup/receivelog.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@ ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi
235235
PQclear(res);
236236
return false;
237237
}
238+
if (PQnfields(res) != 3 || PQntuples(res) != 1)
239+
{
240+
fprintf(stderr, _("%s: could not identify system, got %i rows and %i fields\n"),
241+
progname, PQntuples(res), PQnfields(res));
242+
PQclear(res);
243+
return false;
244+
}
238245
if (strcmp(sysidentifier, PQgetvalue(res, 0, 0)) != 0)
239246
{
240247
fprintf(stderr, _("%s: system identifier does not match between base backup and streaming connection\n"), progname);

0 commit comments

Comments
 (0)