diff options
| author | Peter Eisentraut | 2015-02-24 18:41:07 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2015-02-24 18:41:07 +0000 |
| commit | 23a78352c0a0dc21d6120bd868f0b2d07395b537 (patch) | |
| tree | 1b52cc0ef85206862a287d318934d9aac203ee85 /src/port | |
| parent | 347c74320d10bee458d1fec159aeda7143d31bfb (diff) | |
Error when creating names too long for tar format
The tar format (at least the version we are using), does not support
file names or symlink targets longer than 99 bytes. Until now, the tar
creation code would silently truncate any names that are too long. (Its
original application was pg_dump, where this never happens.) This
creates problems when running base backups over the replication
protocol.
The most important problem is when a tablespace path is longer than 99
bytes, which will result in a truncated tablespace path being backed up.
Less importantly, the basebackup protocol also promises to back up any
other files it happens to find in the data directory, which would also
lead to file name truncation if someone put a file with a long name in
there.
Now both of these cases result in an error during the backup.
Add tests that fail when a too-long file name or symlink is attempted to
be backed up.
Reviewed-by: Robert Hass <robertmhaas@gmail.com>
Diffstat (limited to 'src/port')
| -rw-r--r-- | src/port/tar.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/port/tar.c b/src/port/tar.c index 8ef4f9c388..4721df3ddc 100644 --- a/src/port/tar.c +++ b/src/port/tar.c @@ -49,10 +49,16 @@ tarChecksum(char *header) * must always have space for 512 characters, which is a requirement by * the tar format. */ -void +enum tarError tarCreateHeader(char *h, const char *filename, const char *linktarget, size_t size, mode_t mode, uid_t uid, gid_t gid, time_t mtime) { + if (strlen(filename) > 99) + return TAR_NAME_TOO_LONG; + + if (linktarget && strlen(linktarget) > 99) + return TAR_SYMLINK_TOO_LONG; + /* * Note: most of the fields in a tar header are not supposed to be * null-terminated. We use sprintf, which will write a null after the @@ -141,4 +147,6 @@ tarCreateHeader(char *h, const char *filename, const char *linktarget, * 6 digits, a space, and a null, which is legal per POSIX. */ sprintf(&h[148], "%06o ", tarChecksum(h)); + + return TAR_OK; } |
