Skip to content

Commit d1c1e48

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 ec14081 commit d1c1e48

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/bin/pg_basebackup/t/010_pg_basebackup.pl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
[ 'pg_basebackup', '-D', "$tempdir/backup" ],
1818
'pg_basebackup fails because of hba');
1919

20+
# Some Windows ANSI code pages may reject this filename, in which case we
21+
# quietly proceed without this bit of test coverage.
22+
if (open BADCHARS, ">>$tempdir/pgdata/FOO\xe0\xe0\xe0BAR")
23+
{
24+
print BADCHARS "test backup of file with non-UTF8 name\n";
25+
close BADCHARS;
26+
}
27+
2028
open HBA, ">>$tempdir/pgdata/pg_hba.conf";
2129
print HBA "local replication all trust\n";
2230
print HBA "host replication all 127.0.0.1/32 trust\n";

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy