aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Frost <sfrost@snowman.net>2013-07-15 11:27:20 -0400
committerStephen Frost <sfrost@snowman.net>2013-07-15 11:27:20 -0400
commit2f397a08de49e28e3430ff7278f4648757dea2a3 (patch)
treedb24c207fe944ddd0fbb437e1dbbb1afb227ce42 /src
parent3cb7a393e8e93b1e67bb1e0d361dd1eb7d928ae7 (diff)
downloadpostgresql-2f397a08de49e28e3430ff7278f4648757dea2a3.tar.gz
postgresql-2f397a08de49e28e3430ff7278f4648757dea2a3.zip
Clean up pg_basebackup libpq usage
When using libpq, it's generally preferrable to just use the strings which are in the PQ structures instead of copying them out, so do that instead in BaseBackup(), eliminating the strcpy()'s used there. Also, in ReceiveAndUnpackTarFile(), check the string length for the directory returned by the server for the tablespace path.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_basebackup/pg_basebackup.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index d68e742920c..f1544661c5e 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -509,7 +509,15 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
if (PQgetisnull(res, rownum, 0))
strcpy(current_path, basedir);
else
+ {
+ if (PQgetlength(res, rownum, 1) >= MAXPGPATH)
+ {
+ fprintf(stderr, _("%s: received invalid directory (too long): %s"),
+ progname, PQgetvalue(res, rownum, 1));
+ disconnect_and_exit(1);
+ }
strcpy(current_path, PQgetvalue(res, rownum, 1));
+ }
/*
* Make sure we're unpacking into an empty directory
@@ -814,8 +822,6 @@ BaseBackup(void)
char current_path[MAXPGPATH];
char escaped_label[MAXPGPATH];
int i;
- char xlogstart[64];
- char xlogend[64];
int minServerMajor,
maxServerMajor;
int serverMajor;
@@ -877,11 +883,9 @@ BaseBackup(void)
progname);
disconnect_and_exit(1);
}
- strcpy(xlogstart, PQgetvalue(res, 0, 0));
if (verbose && includewal)
- fprintf(stderr, "xlog start point: %s\n", xlogstart);
+ fprintf(stderr, "xlog start point: %s\n", PQgetvalue(res, 0, 0));
PQclear(res);
- MemSet(xlogend, 0, sizeof(xlogend));
/*
* Get the header
@@ -962,9 +966,8 @@ BaseBackup(void)
progname);
disconnect_and_exit(1);
}
- strcpy(xlogend, PQgetvalue(res, 0, 0));
if (verbose && includewal)
- fprintf(stderr, "xlog end point: %s\n", xlogend);
+ fprintf(stderr, "xlog end point: %s\n", PQgetvalue(res, 0, 0));
PQclear(res);
res = PQgetResult(conn);