diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-25 05:35:44 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2023-04-25 05:45:27 (EDT) |
commit | 28ea2b9718162761b5de617efa74ae2bd020acb2 (patch) | |
tree | db06f233d3e6a3c832f79a84274a12e0ac9d09b6 | |
parent | 2701327cbb9d29e6cd7121fbd1ffee96588aa70b (diff) |
ustar: Ensure listed linkname is NUL-terminated
Also simplify uname and gname copying.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/ustar.c | 10 | ||||
-rw-r--r-- | src/ustar.h | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac index f600715..38c62c2 100644 --- a/configure.ac +++ b/configure.ac @@ -45,7 +45,7 @@ AC_CHECK_FUNCS( [\ fclose feof ferror fopen fprintf fputs fread free fwrite \ localtime malloc memcmp memcpy memset printf puts snprintf \ - sprintf strcmp strftime strlen strncpy strtol + sprintf strcmp strcpy strftime strlen strncpy strtol ], [], [funcs_missing=true]) diff --git a/src/ustar.c b/src/ustar.c index 749af02..c759781 100644 --- a/src/ustar.c +++ b/src/ustar.c @@ -201,7 +201,9 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar, case '2': /* Symbolic link */ (*member)->type = 'l'; strncpy((*member)->linkname, ustar->header.linkname, - sizeof((*member)->linkname)); + sizeof(ustar->header.linkname)); + (*member)->linkname[sizeof((*member)->linkname) - 1] = + '\0'; break; case '3': /* Character special file */ (*member)->type = 'c'; @@ -220,10 +222,8 @@ opkg_opk_ustar_list(struct opkg_opk_ustar *ustar, free(*member); return OPKG_OPK_ERROR; /* Unsupported */ } - strncpy((*member)->uname, ustar->header.uname, - sizeof((*member)->uname)); - strncpy((*member)->gname, ustar->header.gname, - sizeof((*member)->gname)); + strcpy((*member)->uname, ustar->header.uname); + strcpy((*member)->gname, ustar->header.gname); /* Seek through data records until next header record. */ while (ustar->data_size_remaining > 0) { diff --git a/src/ustar.h b/src/ustar.h index 3495d38..220603a 100644 --- a/src/ustar.h +++ b/src/ustar.h @@ -35,7 +35,7 @@ struct opkg_opk_ustar_member { uint64_t size; int64_t mtime; char type; - char linkname[100]; + char linkname[101]; char uname [32]; char gname [32]; struct opkg_opk_ustar_member *next; |