aboutsummaryrefslogtreecommitdiff
path: root/lib/tar/src/read_header.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-02-04 16:30:48 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-02-04 16:43:40 +0100
commit89b367941e12b1163afa517eeddca1b5ecd2a054 (patch)
tree932f6566a0194d0dfe978b378a053e5725ef9ca7 /lib/tar/src/read_header.c
parent72c8155d9fc0eaeac72c053f46ebb7b231d4596a (diff)
libtar: some minor cleanups
- Use is_memory_zero from libutil - Move checksum update function to tar writer code - Move checksum verify function to tar reader code - Only export the function to compute the checksum Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/tar/src/read_header.c')
-rw-r--r--lib/tar/src/read_header.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/tar/src/read_header.c b/lib/tar/src/read_header.c
index ea4873b..219c9fb 100644
--- a/lib/tar/src/read_header.c
+++ b/lib/tar/src/read_header.c
@@ -10,11 +10,14 @@
#include <string.h>
#include <stdlib.h>
-static bool is_zero_block(const tar_header_t *hdr)
+static bool is_checksum_valid(const tar_header_t *hdr)
{
- const unsigned char *ptr = (const unsigned char *)hdr;
+ sqfs_u64 read_chksum;
- return ptr[0] == '\0' && memcmp(ptr, ptr + 1, sizeof(*hdr) - 1) == 0;
+ if (read_octal(hdr->chksum, sizeof(hdr->chksum), &read_chksum))
+ return false;
+
+ return read_chksum == tar_compute_checksum(hdr);
}
static int check_version(const tar_header_t *hdr)
@@ -179,7 +182,7 @@ int read_header(istream_t *fp, tar_header_decoded_t *out)
if ((size_t)ret < sizeof(hdr))
goto out_eof;
- if (is_zero_block(&hdr)) {
+ if (is_memory_zero(&hdr, sizeof(hdr))) {
if (prev_was_zero)
goto out_eof;
prev_was_zero = true;