mirror of
https://github.com/postgres/postgres.git
synced 2025-08-21 10:42:50 +03:00
Truncate strings in tarCreateHeader() with strlcpy(), not sprintf().
This supplements the GNU libc bug #6530 workarounds introduced in commit
54cd4f0457
. 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.
This commit is contained in:
@@ -62,7 +62,7 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
|
|||||||
memset(h, 0, 512); /* assume tar header size */
|
memset(h, 0, 512); /* assume tar header size */
|
||||||
|
|
||||||
/* Name 100 */
|
/* Name 100 */
|
||||||
sprintf(&h[0], "%.99s", filename);
|
strlcpy(&h[0], filename, 100);
|
||||||
if (linktarget != NULL || S_ISDIR(mode))
|
if (linktarget != NULL || S_ISDIR(mode))
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -104,7 +104,7 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
|
|||||||
/* Type - Symbolic link */
|
/* Type - Symbolic link */
|
||||||
sprintf(&h[156], "2");
|
sprintf(&h[156], "2");
|
||||||
/* Link Name 100 */
|
/* Link Name 100 */
|
||||||
sprintf(&h[157], "%.99s", linktarget);
|
strlcpy(&h[157], linktarget, 100);
|
||||||
}
|
}
|
||||||
else if (S_ISDIR(mode))
|
else if (S_ISDIR(mode))
|
||||||
/* Type - directory */
|
/* Type - directory */
|
||||||
@@ -121,11 +121,11 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget,
|
|||||||
|
|
||||||
/* User 32 */
|
/* User 32 */
|
||||||
/* XXX: Do we need to care about setting correct username? */
|
/* XXX: Do we need to care about setting correct username? */
|
||||||
sprintf(&h[265], "%.31s", "postgres");
|
strlcpy(&h[265], "postgres", 32);
|
||||||
|
|
||||||
/* Group 32 */
|
/* Group 32 */
|
||||||
/* XXX: Do we need to care about setting correct group name? */
|
/* XXX: Do we need to care about setting correct group name? */
|
||||||
sprintf(&h[297], "%.31s", "postgres");
|
strlcpy(&h[297], "postgres", 32);
|
||||||
|
|
||||||
/* Major Dev 8 */
|
/* Major Dev 8 */
|
||||||
sprintf(&h[329], "%07o ", 0);
|
sprintf(&h[329], "%07o ", 0);
|
||||||
|
Reference in New Issue
Block a user