set_next_block_after (pointer);
}
+/* Copy at most LEN bytes from SRC to DST. Terminate with NUL unless
+ SRC is LEN characters long */
+static void
+tar_copy_str (char *dst, const char *src, size_t len)
+{
+ dst[len-1] = 0;
+ strncpy (dst, src, len);
+}
+
/* Write a "private" header */
static union block *
start_private_header (const char *name, size_t size)
memset (header->buffer, 0, sizeof (union block));
- strncpy (header->header.name, name, NAME_FIELD_SIZE);
- header->header.name[NAME_FIELD_SIZE - 1] = '\0';
+ tar_copy_str (header->header.name, name, NAME_FIELD_SIZE);
OFF_TO_CHARS (size, header->header.size);
time (&t);
{
union block *header = find_next_block ();
memset (header->buffer, 0, sizeof (union block));
-
- strncpy (header->header.name, st->file_name, NAME_FIELD_SIZE);
- header->header.name[NAME_FIELD_SIZE - 1] = '\0';
+ tar_copy_str (header->header.name, st->file_name, NAME_FIELD_SIZE);
return header;
}
}
i = split_long_name (name, length);
- if (i == 0)
+ if (i == 0 || length - i -1 > NAME_FIELD_SIZE)
{
WARN ((0, 0,
_("%s: file name is too long (cannot be split); not dumped"),
header = find_next_block ();
memset (header->buffer, 0, sizeof (header->buffer));
memcpy (header->header.prefix, name, i);
- memcpy (header->header.name, name + i + 1, length - i);
+ memcpy (header->header.name, name + i + 1, length - i - 1);
return header;
}
static union block *
write_header_name (struct tar_stat_info *st)
{
- if (NAME_FIELD_SIZE <= strlen (st->file_name))
+ if (NAME_FIELD_SIZE < strlen (st->file_name))
return write_long_name (st);
else
return write_short_name (st);
return ((link1->dev ^ link2->dev) | (link1->ino ^ link2->ino)) == 0;
}
-/* Copy at most LEN bytes from SRC to DST. Terminate with NUL unless
- SRC is LEN characters long */
-static void
-tar_copy_str (char *dst, const char *src, size_t len)
-{
- dst[len-1] = 0;
- strncpy (dst, src, len);
-}
-
/* Table of all non-directories that we've written so far. Any time
we see another, we check the table and avoid dumping the data
again if we've done it once already. */
if (type != FIFOTYPE)
{
- MAJOR_TO_CHARS (major (current_stat_info.stat.st_rdev), header->header.devmajor);
- MINOR_TO_CHARS (minor (current_stat_info.stat.st_rdev), header->header.devminor);
+ MAJOR_TO_CHARS (major (current_stat_info.stat.st_rdev),
+ header->header.devmajor);
+ MINOR_TO_CHARS (minor (current_stat_info.stat.st_rdev),
+ header->header.devminor);
}
finish_header (header, block_ordinal);