summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ustar.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/ustar.c b/src/ustar.c
index 13e7621..8c31f7a 100644
--- a/src/ustar.c
+++ b/src/ustar.c
@@ -271,11 +271,12 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
uid_t uid, const char *uname, gid_t gid, const char *gname,
uint64_t size, int64_t mtime, char type, const char *linkname)
{
- size_t linkname_len;
uint32_t chksum;
size_t i;
char *header_uc;
+ memset(&ustar->header, 0, sizeof(ustar->header));
+
if (opkg_opk_dirent_name_prefix(dirent,
ustar->header.name,
sizeof(ustar->header.name),
@@ -296,6 +297,8 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
break;
case 'l': /* Symbolic link */
*ustar->header.typeflag = '2';
+ strncpy(ustar->header.linkname, linkname,
+ sizeof(ustar->header.linkname));
break;
case 'c': /* Character special file */
*ustar->header.typeflag = '3';
@@ -312,14 +315,6 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
default:
return OPKG_OPK_ERROR; /* Unsupported */
}
- if (*ustar->header.typeflag == '2') {
- linkname_len = strlen(linkname);
- memcpy(ustar->header.linkname, linkname, linkname_len);
- } else {
- linkname_len = 0;
- }
- memset(ustar->header.linkname, 0,
- sizeof(ustar->header.linkname) - linkname_len);
strcpy(ustar->header.magic, "ustar");
memcpy(ustar->header.version, "00", 2);