aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2015-06-21 20:04:36 -0400
committerNoah Misch <noah@leadboat.com>2015-06-21 20:04:53 -0400
commitd1c1e48832f31c1a4d01201a31a60c751ed4895c (patch)
treebc7c30a997dda70ac44a5448983e0033129ec7aa /src
parentec1408155d3567b9e9871ad092ea773251d515d9 (diff)
downloadpostgresql-d1c1e48832f31c1a4d01201a31a60c751ed4895c.tar.gz
postgresql-d1c1e48832f31c1a4d01201a31a60c751ed4895c.zip
Truncate strings in tarCreateHeader() with strlcpy(), not sprintf().
This supplements the GNU libc bug #6530 workarounds introduced in commit 54cd4f04576833abc394e131288bf3dd7dcf4806. On affected systems, a tar-format pg_basebackup failed when some filename beneath the data directory was not valid character data in the postmaster/walsender locale. Back-patch to 9.1, where pg_basebackup was introduced. Extant, bug-prone conversion specifications receive only ASCII bytes or involve low-importance messages.
Diffstat (limited to 'src')
-rw-r--r--src/bin/pg_basebackup/t/010_pg_basebackup.pl8
-rw-r--r--src/port/tar.c8
2 files changed, 12 insertions, 4 deletions
diff --git a/src/bin/pg_basebackup/t/010_pg_basebackup.pl b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
index c966de0b741..24a828bb0a3 100644
--- a/src/bin/pg_basebackup/t/010_pg_basebackup.pl
+++ b/src/bin/pg_basebackup/t/010_pg_basebackup.pl
@@ -17,6 +17,14 @@ command_fails(
[ 'pg_basebackup', '-D', "$tempdir/backup" ],
'pg_basebackup fails because of hba');
+# Some Windows ANSI code pages may reject this filename, in which case we
+# quietly proceed without this bit of test coverage.
+if (open BADCHARS, ">>$tempdir/pgdata/FOO\xe0\xe0\xe0BAR")
+{
+ print BADCHARS "test backup of file with non-UTF8 name\n";
+ close BADCHARS;
+}
+
open HBA, ">>$tempdir/pgdata/pg_hba.conf";
print HBA "local replication all trust\n";
print HBA "host replication all 127.0.0.1/32 trust\n";
diff --git a/src/port/tar.c b/src/port/tar.c
index 09fd6c10d34..d664f6440b3 100644
--- a/src/port/tar.c
+++ b/src/port/tar.c
@@ -62,7 +62,7 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
memset(h, 0, 512); /* assume tar header size */
/* Name 100 */
- sprintf(&h[0], "%.99s", filename);
+ strlcpy(&h[0], filename, 100);
if (linktarget != NULL || S_ISDIR(mode))
{
/*
@@ -104,7 +104,7 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
/* Type - Symbolic link */
sprintf(&h[156], "2");
/* Link Name 100 */
- sprintf(&h[157], "%.99s", linktarget);
+ strlcpy(&h[157], linktarget, 100);
}
else if (S_ISDIR(mode))
/* Type - directory */
@@ -121,11 +121,11 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
/* User 32 */
/* XXX: Do we need to care about setting correct username? */
- sprintf(&h[265], "%.31s", "postgres");
+ strlcpy(&h[265], "postgres", 32);
/* Group 32 */
/* XXX: Do we need to care about setting correct group name? */
- sprintf(&h[297], "%.31s", "postgres");
+ strlcpy(&h[297], "postgres", 32);
/* Major Dev 8 */
sprintf(&h[329], "%07o ", 0);