summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-05-02 20:27:14 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-05-02 21:47:41 (EDT)
commit586965c9cdf63170ccc3713ebf87201c46d3428c (patch)
treed33f4de34fcbfcb4ab0d7d1abd266013c75127f6 /src
parent1e0e318b510dcd886b303f23f12652b60f1eb5b9 (diff)
ustar: Fill header with zeroes before populating
Diffstat (limited to 'src')
-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);