Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 45a1d77

Browse files
committed
Truncate strings in tarCreateHeader() with strlcpy(), not sprintf().
This supplements the GNU libc bug #6530 workarounds introduced in commit 54cd4f0. 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.
1 parent 2031931 commit 45a1d77

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/port/tar.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
6262
memset(h, 0, 512); /* assume tar header size */
6363

6464
/* Name 100 */
65-
sprintf(&h[0], "%.99s", filename);
65+
strlcpy(&h[0], filename, 100);
6666
if (linktarget != NULL || S_ISDIR(mode))
6767
{
6868
/*
@@ -104,7 +104,7 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
104104
/* Type - Symbolic link */
105105
sprintf(&h[156], "2");
106106
/* Link Name 100 */
107-
sprintf(&h[157], "%.99s", linktarget);
107+
strlcpy(&h[157], linktarget, 100);
108108
}
109109
else if (S_ISDIR(mode))
110110
/* Type - directory */
@@ -121,11 +121,11 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
121121

122122
/* User 32 */
123123
/* XXX: Do we need to care about setting correct username? */
124-
sprintf(&h[265], "%.31s", "postgres");
124+
strlcpy(&h[265], "postgres", 32);
125125

126126
/* Group 32 */
127127
/* XXX: Do we need to care about setting correct group name? */
128-
sprintf(&h[297], "%.31s", "postgres");
128+
strlcpy(&h[297], "postgres", 32);
129129

130130
/* Major Dev 8 */
131131
sprintf(&h[329], "%07o ", 0);

0 commit comments

Comments
 (0)