summaryrefslogtreecommitdiff
path: root/src/port/tar.c
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:36 -0400
commit4318118edd5582696027f357771e0a8b091fe2bf (patch)
tree140dda22ddd37a99dcce70ddb6d1f84ebf9c8c7d /src/port/tar.c
parentad89a5d115b3b4025f3c135f95f722e7e4becf13 (diff)
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/port/tar.c')
-rw-r--r--src/port/tar.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/port/tar.c b/src/port/tar.c
index 4721df3ddc3..72fd4e13aca 100644
--- a/src/port/tar.c
+++ b/src/port/tar.c
@@ -68,7 +68,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))
{
/*
@@ -110,7 +110,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 */
@@ -127,11 +127,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);