Skip to content
Snippets Groups Projects
Commit 1ccf8652 authored by Natanael Copa's avatar Natanael Copa
Browse files

Revert "abuild-tar: embed checksum for symlinks"

Tar could not handle the headers.

This reverts parts of commit 8b1a5301.
Keep the usage fixes.
parent 97030974
No related merge requests found
......@@ -42,8 +42,6 @@ struct tar_header {
char padding[12]; /* 500-512 */
};
#define MAX_MD_SIZE 20
#define GET_OCTAL(s) get_octal(s, sizeof(s))
#define PUT_OCTAL(s,v) put_octal(s, sizeof(s), v)
......@@ -175,7 +173,7 @@ static int do_it(const EVP_MD *md, int cut)
struct tar_header hdr;
size_t size, aligned_size;
void *ptr;
int r;
int dohash = 0, r;
struct {
char id[4];
uint16_t nid;
......@@ -195,34 +193,22 @@ static int do_it(const EVP_MD *md, int cut)
if (cut && hdr.name[0] == 0)
return 0;
ptr = NULL;
size = GET_OCTAL(hdr.size);
aligned_size = (size + 511) & ~511;
if (md != NULL &&
(hdr.typeflag == '0' || hdr.typeflag == '2' ||
hdr.typeflag == '7')) {
if (md != NULL)
dohash = (hdr.typeflag == '0' || hdr.typeflag == '7');
if (dohash) {
const unsigned char *src;
unsigned char csdata[MAX_MD_SIZE];
int chksum, i;
if (hdr.typeflag == '0' || hdr.typeflag == '7') {
ptr = malloc(aligned_size);
if (full_read(STDIN_FILENO, ptr, aligned_size)
!= aligned_size)
return 1;
memcpy(&hdr.linkname[3], &mdinfo, sizeof(mdinfo));
EVP_Digest(ptr, size, csdata, NULL, md, NULL);
} else {
EVP_Digest(hdr.linkname, strlen(hdr.linkname),
csdata, NULL, md, NULL);
}
ptr = malloc(aligned_size);
if (full_read(STDIN_FILENO, ptr, aligned_size) != aligned_size)
return 1;
/* Embed to header */
memcpy(&hdr.devmajor, &mdinfo, sizeof(hdr.devmajor));
memcpy(&hdr.devminor, &csdata[0], sizeof(hdr.devminor));
memcpy(&hdr.padding, &csdata[sizeof(hdr.devminor)], sizeof(hdr.padding));
memcpy(&hdr.linkname[3], &mdinfo, sizeof(mdinfo));
EVP_Digest(ptr, size, &hdr.linkname[3+sizeof(mdinfo)],
NULL, md, NULL);
/* Recalculate checksum */
memset(hdr.chksum, ' ', sizeof(hdr.chksum));
......@@ -235,7 +221,7 @@ static int do_it(const EVP_MD *md, int cut)
if (full_write(STDOUT_FILENO, &hdr, sizeof(hdr)) != sizeof(hdr))
return 2;
if (ptr != NULL) {
if (dohash) {
if (full_write(STDOUT_FILENO, ptr, aligned_size) != aligned_size)
return 2;
free(ptr);
......@@ -285,10 +271,6 @@ int main(int argc, char **argv)
md = EVP_get_digestbyname(digest);
if (md == NULL)
return usage();
if (EVP_MD_size(md) > MAX_MD_SIZE) {
fprintf(stderr, "digest size is too large\n");
return -1;
}
}
return do_it(md, cut);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment